Back to Devexpress

ColumnView.GetColumnHeaderBestWidth(GridColumn) Method

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-dot-getcolumnheaderbestwidth-x28-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-x29.md

latest3.3 KB
Original Source

ColumnView.GetColumnHeaderBestWidth(GridColumn) Method

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

Namespace : DevExpress.XtraGrid.Views.Base

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

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

Parameters

NameTypeDescription
columnGridColumn

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

|

Returns

TypeDescription
Int32

An integer value that specifies the width.

|

Remarks

The GridColumn.GetHeaderBestWidth and ColumnView.GetColumnHeaderBestWidth(GridColumn) 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
gridControl1.LookAndFeel.StyleChanged += LookAndFeel_StyleChanged1;

private void LookAndFeel_StyleChanged1(object sender, EventArgs e) {
    gridColumn1.Width = gridColumn1.GetHeaderBestWidth();
    //gridColumn1.Width = gridView1.GetColumnHeaderBestWidth(gridColumn1);
}
vb
AddHandler gridControl1.LookAndFeel.StyleChanged, AddressOf LookAndFeel_StyleChanged1

Private Sub LookAndFeel_StyleChanged1(ByVal sender As Object, ByVal e As EventArgs)
    gridColumn1.Width = gridColumn1.GetHeaderBestWidth()
    'gridColumn1.Width = gridView1.GetColumnHeaderBestWidth(gridColumn1)
End Sub

See Also

GetHeaderBestWidth()

BestFitColumns()

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace