Skip to main content

Accessing and Identifying Columns

  • 2 minutes to read

#Identifying Columns

The table below lists properties and XAML attributes that allow you to identify grid columns.

Identifiers

Description

x:Name

Uniquely identifies a column, so that it can be accessed from code-behind or general code.


<dxg:GridColumn x:Name="colProduct" FieldName="ProductName"/>

ColumnBase.FieldName

Specifies the name of a data source field to which a column is bound. Note that a grid can display multiple columns bound to the same data field.

GridViewBase.FocusedColumn

Returns the focused column.

#Accessing Columns

If a column is created at design time, you can specify its unique name using the x:Name attribute. In this instance, a column can be accessed by its name from code-behind:


<dxg:GridControl.Columns>
    <dxg:GridColumn x:Name="colProduct" FieldName="ProductName"/>
    <dxg:GridColumn x:Name="colUnitPrice" FieldName="UnitPrice"/>
</dxg:GridControl.Columns>

Since columns are contained within the grid's GridControl.Columns collection, individual columns can be accessed by the field name or using indexed notation.


<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="ProductName"/>
    <dxg:GridColumn FieldName="UnitPrice"/>
</dxg:GridControl.Columns>

A focused column can be accessed using the GridViewBase.FocusedColumn property.

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 a Column Chooser are stored within a view's DataViewBase.ColumnChooserColumns read-only collection. Individual columns can be accessed using indexed notation.