TableView.BestFitColumn(BaseColumn) Method
Resizes the specified column to the minimum width required to display the column’s contents completely.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.2.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
column | BaseColumn | A GridColumn representing the grid column whose width should be optimized. |
Remarks
The BestFitColumn method calculates the minimum width that is required to accommodate the content of the following elements: column header, summary footer cell, data cells. Areas, which are taken into account, are specified by the TableView.BestFitArea property.
Note that the number of processed data cells depends upon the TableView.BestFitMaxRowCount property value. If set to -1, all data cells are processed. If set to a positive integer, the property specifies the number of cells to be processed. Cells are processed starting from the top visible row.
When the auto width feature is applied to the view, column element contents may not be displayed completely after calling BestFitColumn. The reason is that total column width always matches the View width - while columns have a minimum allowed width and may have a fixed width. Refer to the BaseColumn.MinWidth and BaseColumn.FixedWidth properties for details on column width restrictions.
Note also that the calculated column width cannot exceed the current View width. Finally, the BestFitColumn method cannot resize columns to widths less than that specified by the BaseColumn.MinWidth property.
Your end-users can also apply best fit to columns. They need to double-click the desired column’s right edge or choose the Best Fit item from the column header’s context menu for this purpose. The column’s BaseColumn.FixedWidth option must be disabled and the BaseColumn.AllowResizing option must be enabled to activate this functionality.
Note
The BestFitColumn method should only be called when the grid is loaded.
Refer to the Best Fit topic to learn more.