Hiding and Displaying Columns
- 2 minutes to read
Columns are represented by GridColumn objects. To hide a column, set its BaseColumn.Visible property to false. If a column's ColumnBase.ShowInColumnChooser option is enabled, its header (when the column is hidden) is displayed within the Column Chooser.
To show a hidden column, set its BaseColumn.Visible property to true. To show it at a specified position among visible columns, use its BaseColumn.VisibleIndex property.
A hidden column displayed within the Column Chooser can also be shown within a view, using the DataViewBase.MoveColumnTo method.
if (grid.View.ColumnChooserColumns.Count == 0) return;
GridColumn column = grid.View.ColumnChooserColumns[0];
grid.View.MoveColumnTo(column, 1,
HeaderPresenterType.ColumnChooser,
HeaderPresenterType.Headers);
#End-User Capabilities
An end-user can temporarily hide columns by dragging their headers to the Column Chooser. The Column Chooser can be shown via a column header's popup menu. Dragging a column's header from the Column Chooser to a header panel shows the column within a view.
To allow an end-user to hide columns, the following options must be enabled.
If the DataViewBase.AllowMoveColumnToDropArea property is set to true, an end-user can hide a column by dropping its header outside the View.
#Accessing Visible and Hidden Columns
The grid stores its columns (visible and hidden) within the GridControl.Columns collection. Individual columns can be accessed by a field name or via indexed notation.
To access only visible columns (whose BaseColumn.Visible property is set to true), use a view's GridViewBase.VisibleColumns property. This property returns a list containing GridColumn objects that correspond to columns displayed within a view. Individual columns can be accessed using indexed notation.
Hidden columns that are displayed within the Column Chooser are stored within a view's DataViewBase.ColumnChooserColumns read-only collection. Individual columns can be accessed using indexed notation.