Skip to main content

Columns Layout and Width

  • 4 minutes to read

DXGrid for Silverlight provides two options that, if enabled, allow end-users to modify the layout of columns within a Table View. The DataViewBase.AllowMoving option controls whether or not end-users can change the visible position of columns via drag and drop. The TableView.AllowResizing option controls whether end-users can resize columns or not by dragging the right edge of their headers.

Individual columns provide the BaseColumn.AllowMoving and BaseColumn.AllowResizing options that, if specified, take priority over the view's corresponding options. For instance, you can prevent individual columns from being moved by an end-user.

#Column Position

Columns are identified by their headers. Column headers are displayed if a view's DataViewBase.ShowColumnHeaders property is set to true.

By default, columns are displayed within a view in the same order they appear in the GridControl.Columns collection. If column moving is allowed, end-users can reorder columns by dragging their headers.

ColumnsLayout_MoveColumn

To move a column in code, use the DataViewBase.MoveColumnTo method.

To hide a column, set its BaseColumn.Visible property to false. End-users can temporarily hide individual columns via the Column Chooser. To learn more, see Showing and Hiding Columns.

#Column Width

Column widths can be changed automatically, so that the total columns' width matches the grid's width. In this instance, changing the width of one column automatically changes the widths of other columns. This behavior is controlled by the view's TableView.AutoWidth property. To obtain the actual width of columns, use their BaseColumn.ActualWidth property.

To prevent the width of an individual column(s) from being changed when resizing other columns, you should set its BaseColumn.FixedWidth property to true. Use the BaseColumn.MinWidth property to specify the minimum width.

If the automatic column width calculation is disabled, a column's width is specified by its BaseColumn.Width property. If the total column width exceeds a grid's width, a horizontal scrollbar is displayed, allowing an end-user to scroll grid columns.

If you want a column (or columns) to always be displayed onscreen, regardless of scrolling, set its BaseColumn.Fixed property.

FixedColumns_Animation

For detailed information, see Fixed Columns.

#Best Fit

Table Views provide the capability to automatically calculate and apply the optimal width required for a column to completely display its contents. The Best Fit feature can be applied to an individual column, as well as to all columns displayed within a Table View. To enable this feature for all visible columns or individual columns, use the TableView.AllowBestFit and ColumnBase.AllowBestFit properties.

Use the TableView.BestFitArea (ColumnBase.BestFitArea) property to specify interface elements (column header, cells, etc.), which should be taken into account when adjusting column width.

If cell values are taken into account when calculating a column's optimal width, you can specify the way this width is calculated. To do this, use the TableView.BestFitMode (ColumnBase.BestFitMode) property. By default, a column's width is calculated based on text of all cells within this column.

To increase an application's performance, the number of records taken into account when calculating the optimal width can be limited by setting the TableView.BestFitMaxRowCount (ColumnBase.BestFitMaxRowCount) property. By default, this property is set to NaN to indicate that all cells are processed. If the TableView.BestFitMaxRowCount property is set to a positive value, a View processes the specified number of cells starting from the top visible cell.

The following table lists members that relate to the Best Fit feature.

Method Description
ColumnBase.BestFitWidth Specifies a column's width when the Best Fit feature is applied to this column.
TableView.BestFitColumn Resizes a specified column to the optimal width required to display its contents completely.
TableView.BestFitColumns Resizes all columns displayed within a View to the optimal width required to display their contents completely.
TableView.CalcColumnBestFitWidth Returns a column's optimal width required to display its contents completely.
TableView.CustomBestFit Enables you to manually calculate the optimal width for a column(s).

End-users can resize columns to their optimal width (if allowed) by double clicking their right border or using the column header context menu.

NOTE

The Best Fit feature cannot be applied to a column if a column's BaseColumn.FixedWidth property is set to true and/or the BaseColumn.AllowResizing property is set to 'False'.