Back to Devexpress

TreeList.BestFitColumns() Method

windowsforms-devexpress-dot-xtratreelist-dot-treelist-ad45d0a3.md

latest7.7 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
public virtual void BestFitColumns()
vb
Public Overridable Sub 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.

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.

winforms-treelist-unbound-columns/CS/TreeList_UnboundDataViaEvent/Form1.cs#L42

csharp
treeList1.ForceInitialize();
    treeList1.BestFitColumns();
}

excel-export-api-examples/CS/XLExportExamples/Form1.cs#L138

csharp
treeList1.ExpandAll();
    treeList1.BestFitColumns();
}

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/CS/ConditionalFormatting_Example/Form1.cs#L53

csharp
treeList1.ExpandAll();
    treeList1.BestFitColumns();
}

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/CS/SpreadsheetControl/Form1.cs#L58

csharp
treeList1.ExpandAll();
    treeList1.BestFitColumns();
}

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/Form1.cs#L111

csharp
treeList1.ExpandAll();
    treeList1.BestFitColumns();
}

winforms-treelist-unbound-columns/VB/TreeList_UnboundDataViaEvent/Form1.vb#L37

vb
treeList1.ForceInitialize()
    treeList1.BestFitColumns()
End Sub

excel-export-api-examples/VB/XLExportExamples/Form1.vb#L138

vb
treeList1.ExpandAll()
    treeList1.BestFitColumns()
End Sub

spreadsheet-document-api-apply-conditional-formatting-to-cell-range/VB/ConditionalFormatting_Example/Form1.vb#L48

vb
treeList1.ExpandAll()
    treeList1.BestFitColumns()
End Sub

winforms-spreadsheet-apply-conditional-formatting-to-a-range-of-cells/VB/SpreadsheetControl/Form1.vb#L54

vb
treeList1.ExpandAll()
    treeList1.BestFitColumns()
End Sub

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/Form1.vb#L106

vb
treeList1.ExpandAll()
    treeList1.BestFitColumns()
End Sub

See Also

BestFit()

BestFitNodes

Width

AutoWidth

BestFitMode

BestFitUseErrorInfo

GetColumnHeaderBestWidth

GetHeaderBestWidth()

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace