Skip to main content

TreeList.BestFitColumns() Method

Modifies the width of each visible column so that the contents of its cells are not truncated, if possible.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v23.2.dll

NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

public virtual void BestFitColumns()

Remarks

Call the BestFitColumns method to resize the columns so that they completely display their contents. Note that columns are resized to the minimum width required. If the TreeListOptionsView.AutoWidth option is enabled, columns change their width with respect to the contents of their cells, but the total width of all columns remains equal to the control’s width. So, cell values may appear truncated after a call to the BestFitColumns method in such circumstances. There can also be situations when columns are wider than required to accommodate the contents of their cells.

If the TreeListOptionsView.AutoWidth option is disabled, columns get the width required to display their cell values without truncating them.

The TreeListOptionsView.BestFitNodes property specifies which nodes are taken into account when searching for the widest column cell.

Note: the BestFitColumns method changes the width of all columns, including the columns whose TreeListOptionsColumn.AllowSize option is disabled.

The image below displays the effect of the BestFitColumns method call.

Columns - BestFitColumns

If you want to display specific column cells without truncating their values, use the TreeListColumn.BestFit method of the desired column.

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.

The following code snippets (auto-collected from DevExpress Examples) contain references to the BestFitColumns() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also