Back to Devexpress

TableView.BestFitColumns() Method

wpf-devexpress-dot-xpf-dot-grid-dot-tableview-689ca8c5.md

latest2.7 KB
Original Source

TableView.BestFitColumns() Method

Resizes all visible columns to optimally fit their contents.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public void BestFitColumns()
vb
Public Sub BestFitColumns

Remarks

Tip

Topic : Best Fit

Call the BestFitColumns method to resize the columns so that they display their contents completely.

csharp
private static void TableViewOnLoaded(object sender, EventArgs e) {
    var tableView = sender as TableView;
    if(tableView != null) {
        foreach(var item in tableView.VisibleColumns) {
            tableView.BestFitColumn(item);
        }
    }
}
vb
Private Shared Sub TableViewOnLoaded(ByVal sender As Object, ByVal e As EventArgs)
    Dim tableView = TryCast(sender, TableView)
    If tableView IsNot Nothing Then
        For Each item In tableView.VisibleColumns
            tableView.BestFitColumn(item)
        Next
    End If
End Sub

Columns are resized to the minimum width required. The content taken into account when calculating the required column width includes the column header contents, data cell contents, and the footer summary cell’s content. If the TableView.BestFitMaxRowCount property value is -1 , all data cells are processed. Otherwise, the View only processes the number of cells specified by that property value.

If the BaseColumn.FixedWidth property is true , the column is not resized when calling the BestFitColumns method.

To apply the best width feature to a particular column, call the TableView.BestFitColumn method.

Note

The BestFitColumns method should be called only when the GridControl is loaded.

See Also

BestFitColumn(BaseColumn)

TableView Class

TableView Members

DevExpress.Xpf.Grid Namespace