Back to Devexpress

TreeList.GetColumnHeaderBestWidth(TreeListColumn) Method

windowsforms-devexpress-dot-xtratreelist-dot-treelist-dot-getcolumnheaderbestwidth-x28-devexpress-dot-xtratreelist-dot-columns-dot-treelistcolumn-x29.md

latest3.3 KB
Original Source

TreeList.GetColumnHeaderBestWidth(TreeListColumn) Method

Returns the column header width that allows the content to be displayed in its entirety.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
public int GetColumnHeaderBestWidth(
    TreeListColumn column
)
vb
Public Function GetColumnHeaderBestWidth(
    column As TreeListColumn
) As Integer

Parameters

NameTypeDescription
columnTreeListColumn

An object that specifies the column for which to calculate the width.

|

Returns

TypeDescription
Int32

An integer value that specifies the width.

|

Remarks

The TreeListColumn.GetHeaderBestWidth and TreeList.GetColumnHeaderBestWidth(TreeListColumn) methods return the header width that allows the header content to be displayed in its entirety. For example, since different skins may have different optimal header widths, you can use these methods to recalculate a column’s width when the current skin changes.

Example

The code below shows how to automatically update the column width when look and feel settings change.

csharp
treeList1.LookAndFeel.StyleChanged += LookAndFeel_StyleChanged;

private void LookAndFeel_StyleChanged(object sender, EventArgs e) {
    treeListColumn1.Width = treeListColumn1.GetHeaderBestWidth();
    //treeListColumn1.Width = treeList1.GetColumnHeaderBestWidth(treeListColumn1);
}
vb
AddHandler treeList1.LookAndFeel.StyleChanged, AddressOf LookAndFeel_StyleChanged

Private Sub LookAndFeel_StyleChanged(ByVal sender As Object, ByVal e As EventArgs)
    treeListColumn1.Width = treeListColumn1.GetHeaderBestWidth()
    'treeListColumn1.Width = treeList1.GetColumnHeaderBestWidth(treeListColumn1)
End Sub

See Also

GetHeaderBestWidth()

BestFitColumns()

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace