Back to Devexpress

Show and Hide Columns

wpf-6318-controls-and-libraries-data-grid-grid-view-data-layout-columns-and-card-fields-show-and-hide-columns.md

latest3.9 KB
Original Source

Show and Hide Columns

  • Jun 13, 2023
  • 2 minutes to read

In Code

Set the BaseColumn.Visible property to false to hide a column or a band from the GridControl. To hide a column or a band from the Column Chooser , set the column’s BaseColumn.ShowInColumnChooser property to false.

xaml
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="Name" IsSmart="True"/>
    <dxg:GridColumn FieldName="City" IsSmart="True">
        ...
    </dxg:GridColumn>
    <dxg:GridColumn FieldName="Visits" IsSmart="True" Visible="False"/>
    <dxg:GridColumn FieldName="Birthday" IsSmart="True" Visible="False" ShowInColumnChooser="False">
        ...
    </dxg:GridColumn>
</dxg:GridControl.Columns>

You can sort data against hidden columns with the GridSortInfo.SortOrder property:

xaml
<dxg:GridColumn FieldName="Visits" IsSmart="True" SortOrder="Ascending" Visible="False"/>

Use the GridControl.Columns property to get all GridControl columns (visible and hidden). Use the GridViewBase.VisibleColumns property to get visible columns. You can access individual columns and bands by name or index.

Column Chooser

The Column Chooser allows end users to hide and show columns from the GridControl at runtime. Refer to the Show and Hide Columns topic for more information.

APIDescription
DataViewBase.ShowColumnChooserShows the Column Chooser. After you show the Column Chooser , the GridControl raises the DataViewBase.ShownColumnChooser event.
DataViewBase.HideColumnChooserHides the Column Chooser. After you hide the Column Chooser , the GridControl raises the DataViewBase.HiddenColumnChooser event.
DataViewBase.IsColumnChooserVisibleGets or sets whether the Column Chooser is visible.
DataViewBase.ColumnChooserTemplateA template that defines the Column Chooser ‘s presentation.
ColumnBase.ColumnChooserHeaderCaptionThe column header caption displayed in the Column Chooser.
DataViewBase.ColumnChooserColumnsA list of columns displayed in the Column Chooser.
DataViewBase.ColumnChooserColumnDisplayModeThe Column Chooser ‘s display mode (ShowAllColumns, ShowHiddenColumnsOnly).
TableView.ShowBandsInCustomizationFormShows the Bands tab in the Column Chooser (in the ShowHiddenColumnsOnly mode).

Customization