Best Fit
- 3 minutes to read
The GridControl can calculate and apply the optimal width required for a column or band to display all its contents.
You can apply the Best Fit feature to:
Note
You cannot apply the Best Fit feature to a column if:
- The BaseColumn.FixedWidth property is set to true
- The BaseColumn.AllowResizing property is set to false.
Applying Best Fit
At Runtime
End-users can do the following to apply Best Fit to a column (or band):
Double click the column (or band) header’s right border:
Right-click the column (or band) header and select the Best Fit item in the invoked context menu:
In Code
The following methods allow you to apply the Best Fit feature:
Method | Description |
---|---|
TableView.BestFitColumn (TreeListView.BestFitColumn) | Resizes the specified column to the optimal width required to display all its contents. |
TableView.BestFitColumns (TreeListView.BestFitColumns) | Resizes all columns displayed within the current View to the optimal width required to display their contents. |
Use these methods after the GridControl has been loaded.
Allowing Best Fit
You and your end-users can apply Best Fit to any column by default. You can set the following properties to false to forbid end-users to apply Best Fit for a required column or all columns:
Property | Description |
---|---|
BaseColumn.AllowBestFit | Gets or sets whether it is allowed to calculate an optimal width and apply it to the column. |
TableView.AllowBestFit (TreeListView.AllowBestFit) | Gets or sets whether it is allowed to calculate the optimal widths and apply them to all columns in a View. |
Best Fit Options
The GridControl has a set of members that allow you to control the Best Fit feature manually:
Property | Description |
---|---|
TableView.BestFitArea, TreeListView.BestFitArea, ColumnBase.BestFitArea | Allows specifying interface elements (column header, cells, etc.) which should be taken into account when adjusting column widths. |
TableView.BestFitMode, TreeListView.BestFitMode, ColumnBase.BestFitMode | If cell values are taken into account when calculating a column’s optimal width, you can specify the way this width is calculated. A column’s width is calculated based on all cells’ text within this column by default. |
TableView.BestFitMaxRowCount, TreeListView.BestFitMaxRowCount, ColumnBase.BestFitMaxRowCount | You can increase the application’s performance by limiting the number of records taken into account when calculating the optimal width. This property is set to NaN by default to indicate that all cells are processed. If the property is set to a positive value, a View processes the specified number of cells starting from the top visible cell. |
BaseColumn.BestFitWidth | Specifies a column’s width when the Best Fit feature is applied to this column. |
TableView.CalcColumnBestFitWidth (TreeListView.CalcColumnBestFitWidth) | Returns the column’s optimal width required to display all its contents. |
TableView.CustomBestFit (TreeListView.CustomBestFit) | Allows you to manually calculate the optimal width for a column(s). |