Adjusts the TreeListColumn width to display the contents of the column's cells, header and summaries optimally.
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:
If the TreeList control is created at design time, changing the visual settings and size of the control and its elements (e.g., invoking the best fit functionality) is not in effect before 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.