Back to Devexpress

Access and Identify Columns

wpf-6095-controls-and-libraries-data-grid-grid-view-data-layout-columns-and-card-fields-access-and-identify-columns.md

latest2.7 KB
Original Source

Access and Identify Columns

  • Aug 12, 2021
  • 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.

xaml
<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:

xaml
<dxg:GridControl.Columns>
    <dxg:GridColumn x:Name="colProduct" FieldName="ProductName"/>
    <dxg:GridColumn x:Name="colUnitPrice" FieldName="UnitPrice"/>
</dxg:GridControl.Columns>
csharp
colUnitPrice.AllowMoving = DevExpress.Utils.DefaultBoolean.False;
vb
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:

xaml
<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="ProductName"/>
    <dxg:GridColumn FieldName="UnitPrice"/>
</dxg:GridControl.Columns>
csharp
GridColumn colProduct = grid.Columns["ProductName"];
GridColumn colPrice = grid.Columns[1];
vb
Dim colProduct As GridColumn = grid.Columns("ProductName")
Dim colPrice As GridColumn = grid.Columns(1)

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