Mixing BestFit and Fill Modes for the GridView's Columns
Environment
Product Version | Product | Author |
---|---|---|
2021.1.223 | RadGridView for WinForms | Desislava Yordanova |
Description
RadGridView supports two ways of auto sizing the columns:
AutoSizeColumnsMode: columns can automatically fill the entire width of the grid. Just set the AutoSizeColumnsMode property of the desired template to GridViewAutoSizeColumnsMode.Fill.
Best fit: the column widths can be set to fit its content by using the GridViewTemplate.BestFitColumns(BestFitColumnMode mode) or GridViewDataColumn.BestFit methods. This mode distributes algorithm that attempts to fit in the header text and column data for all visible rows.
The BestFitColumnMode controls which cells participate in the calculations for the space required to fit the text. These are the available modes:
BestFitColumnMode.None - The column's width does not adjust automatically.
BestFitColumnMode.AllCells - The column's width adjusts to fit the contents of all cells in the control.
BestFitColumnMode.DisplayedDataCells - The column's width adjusts to fit the contents of the displayed data cells.
BestFitColumnMode.HeaderCells - The column's width adjusts to fit the contents of the header cell.
BestFitColumnMode.FilterCells - The column's width adjusts to fit the contents of the filter cell.
BestFitColumnMode.SummaryRowCells - The column's width adjusts to fit the contents of the summary row cell.
BestFitColumnMode.SystemCells - The column's width adjusts to fit the contents of the system cells.
BestFitColumnMode.DisplayedCells - The column's width adjusts to fit the contents of the displayed cells.
Mixing the two ways is not possible as they follow different principle for sizing. However, this article demonstrates a sample approach how to best-fit the columns considering the columns' headers and adjust the last column's width so that it fills the available space.
Solution
You can best fit the columns and manually adjust the last column's width according to the remaining space. Thus, you can simulate best fitting the columns and filling the grid's width. It is necessary to subscribe to the RadGridView.SizeChanged event and recalculate the last column's width.