When working with GridControl, you may need to write code that accesses particular column properties or that passes column objects as method parameters, etc. You may also require column objects for event parameters. This topic provides information on how to access and identify columns programmatically.
The table below lists properties and XAML attributes that allow you to identify grid columns.
Uniquely identifies a column so that it can be accessed from code-behind or general code.
Specifies the name of a data source field to which a column is bound.
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:
<dxGrid:GridControl.Columns> <dxGrid:TextColumn x:Name="colProduct" FieldName="ProductName"/> <dxGrid:NumberColumn x:Name="colUnitPrice" FieldName="UnitPrice"/> </dxGrid:GridControl.Columns>
Since columns are contained within the grid's GridControl.Columns collection, an individual column can be accessed by the name of the field to which the required column is bound, or using indexed notation:
<dxg:GridControl.Columns> <dxg:TextColumn FieldName="ProductName"/> <dxg:NumberColumn FieldName="UnitPrice"/> </dxg:GridControl.Columns>
The column collection also provides the GridColumnCollection.GetColumnByFieldName method to access columns by field names.
To provide a column as a parameter for the following methods, you can pass a column object or string that specifies a column field name.