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

User (Old forums)
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;
fColumnToExtend.MinWidth = 0;
fColumnToExtend.MaxWidth = -1;
fColumnToExtend.Width = lTotalWidth;
fColumnToExtend.MinWidth = lTotalWidth;
fColumnToExtend.MaxWidth = lTotalWidth;
finally { fExtendingColumn = false; }

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