TreeListColumn.BestFit() Method
Adjusts the TreeListColumn width to display the contents of the column’s cells, header and summaries optimally.
Namespace: DevExpress.XtraTreeList.Columns
Assembly: DevExpress.XtraTreeList.v24.2.dll
Declaration
Remarks
The BestFit method adjusts the width of a specific column to display the contents of its cells optimally. This method determines the largest element in the column and tries to set the column’s width so as to fully display this element.
If the TreeListOptionsView.AutoWidth option is disabled, the column’s width is set to the largest element’s width.
The BestFit method calculates the minimum width required to accommodate the content of the following elements:
- column header;
- summary footer cell;
- data cells.
If the TreeListOptionsView.AutoWidth option is enabled, the column’s width is changed but not necessarily set to the largest element’s width. It is changed so that the widths of other columns are not less than their minimum widths (TreeListColumn.MinWidth).
Consider the following example, where cells in the “Department” column are trimmed.
A call to the BestFit method for the “Department” column resizes the column to display its contents in their entirety:
To invoke the “best fit” functionality for all columns, use TreeList.BestFitColumns.
At runtime, an end-user can double-click the right edge of a target column header to invoke the “best fit” functionality.
Another way to invoke the “best fit” feature is to use the column context menu:
Note
If the TreeList control is created at design time, you cannot change the visual settings or size of the control and its elements (for example, by invoking the best fit functionality) until the Tree List has completed its initialization. To customize these settings in the form’s System.Windows.Forms.Form.Load event handler, call the TreeList.ForceInitialize method prior to performing additional customization.