Skip to main content

Access and Identify Columns

  • 2 minutes to read

Identify Columns

The table below lists properties and XAML attributes that allow you to identify grid columns (or card fields in a Card View).

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 the grid can display multiple columns bound to the same data field.

GridControl.Columns

Returns a collection of the GridControl‘s columns.

DataControlBase.CurrentColumn

Returns the focused column.

GridViewBase.VisibleColumns

Returns a list of columns displayed in the GridControl.

Access 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>
colUnitPrice.AllowMoving = DevExpress.Utils.DefaultBoolean.False;

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

<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="ProductName"/>
    <dxg:GridColumn FieldName="UnitPrice"/>
</dxg:GridControl.Columns>
GridColumn colProduct = grid.Columns["ProductName"];
GridColumn colPrice = grid.Columns[1];

The focused column can be accessed using the DataControlBase.CurrentColumn property.