Home Forums WinForms controls Xceed Grid for WinForms How do I have a column fill remaining width?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15274 |

    I have a few instances where I have large grids that only have a few columns, so is there a way to have a specific column index take up the remaining screen width?

    I have a function that KINDA does this, but it’s not 100% and doesn’t take into consideration groupings, detail grids, or if a scrollbar is already visible.

    Anyone have any ideas or know of a property I am missing?

    Imported from legacy forums. Posted by Rock (had 3559 views)

    User (Old forums)
    Member
    Post count: 23064

    There is no property you can set to get a column to fill the available space. You need to handle this yourself.

    Basically, you need to calculate the space that is left and set your last column’s width to it. You need to use the GridControl ClientRectangle, minus the RowSelectorPane, if applicable the VerticalScrollbar, and the Visible Columns. You will need to handle the ScrollBarsChanged event to change the width when the scroll bar appears/disappears.

    Imported from legacy forums. Posted by André (had 416 views)

    User (Old forums)
    Member
    Post count: 23064

    The following method will calculate set the width of 1 column to the available space. You should call it:
    – The first time after you set the fColumnToExtend variable
    – When the width or visible index of a column changes (events WidthChanged and VisibleIndexChanged on Column)
    – When the grid resizes (event Resize on GridControl)
    – When the first visible column of the grid changes (event FirstVisibleColumnChanged on GridControl)<pre>Column fColumnToExtend;
    bool fExtendingColumn;
    void ExtendColumn()
    {
    if (fColumnToExtend != null && !fExtendingColumn && fColumnToExtend.Visible)
    {
    int lTotalWidth = grid.DisplayRectangle.Width;
    foreach(Column lColumn in grid.Columns)
    if (lColumn != fColumnToExtend && lColumn.Visible)
    lTotalWidth -= lColumn.Width;

    foreach(Group lGroupTemplate in grid.GroupTemplates)
    lTotalWidth -= lGroup.SideMargin.Width;

    if (grid.RowSelectorPane.Visible)
    lTotalWidth -= grid.RowSelectorPane.Width;

    if (grid.FixedColumnSplitter.Visible)
    lTotalWidth -= grid.FixedColumnSplitter.Width;

    if (lTotalWidth > 0)
    {
    fExtendingColumn = true;
    try
    {
    fColumnToExtend.MinWidth = 0;
    fColumnToExtend.MaxWidth = -1;
    fColumnToExtend.Width = lTotalWidth;
    fColumnToExtend.MinWidth = lTotalWidth;
    fColumnToExtend.MaxWidth = lTotalWidth;
    }
    finally { fExtendingColumn = false; }
    }
    }
    }</pre>

    Imported from legacy forums. Posted by Tommy (had 2913 views)

    User (Old forums)
    Member
    Post count: 23064

    I was faced with similar problem before.
    And If the VerticalScrollBar mentioned is applicable, here is how you detect if a vertical scroll bar is visible

    foreach (Control c in _legendgridControl.Controls)
    {
    if (c.GetType().ToString() == “Xceed.Grid.Controls.WinVerticalScrollBar”)
    {
    return c.Visible;
    }
    }
    return false;

    You can not right (c is Xceed.Grid.Controls.WinVerticalScrollBar) because Xceed.Grid.Controls.WinVerticalScrollBar is internal.

    The width of the scroll bar is SystemInformation.VerticalScrollBarWidth or you can also return it from the loop above as c.Width.

    You may have to subscribe to teh visible changed event of teh scroll bar because it is usually shown after the resize event. In that case something like this will work,

    foreach (Control scrollBar in _legendgridControl.Controls)
    {
    if (scrollBar.GetType().ToString() == “Xceed.Grid.Controls.WinVerticalScrollBar”)
    {
    scrollBar.VisibleChanged += new EventHandler(scrollBar_VisibleChanged);
    }
    }

    Imported from legacy forums. Posted by userX (had 509 views)

    User (Old forums)
    Member
    Post count: 23064

    Works like a charm

    Thank you all for your quick help!

    Imported from legacy forums. Posted by Rock (had 4399 views)

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.