GridColumnCollection.ColumnByFieldName(String) Method
Returns a column that is bound to the specified data field.
Namespace: DevExpress.XtraGrid.Columns
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
fieldName | String | The data field name. |
Returns
Type | Description |
---|---|
GridColumn | A GridColumn object that represents the column bound to the specified data field. null (Nothing in Visual Basic) if the collection does not contain a column bound to the specified data field. |
Remarks
The ColumnByFieldName
method scans the View’s Columns
collection and returns the column whose FieldName property matches the specified data field.
DevExpress.XtraGrid.Columns.GridColumn column = gridView1.Columns.ColumnByFieldName("MyDataField");
If the View’s Columns
collection contains multiple columns bound to the same data field, the ColumnByFieldName
method returns the outermost column of those columns:
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
public Form1() {
InitializeComponent();
CreateGridColumns(gridView1);
GridColumn column = gridView1.Columns.ColumnByFieldName("DataField1");
// column = gridColumn3
}
void CreateGridColumns(GridView view){
view.Columns.Clear(); ;
view.Columns.AddRange(new GridColumn[] {
new GridColumn(){ Name = "gridColumn1", FieldName = "DataField1", Visible = true },
new GridColumn(){ Name = "gridColumn2", FieldName = "DataField2", Visible = true },
new GridColumn(){ Name = "gridColumn3", FieldName = "DataField1", Visible = true }
});
}
To find a column by its name, use the ColumnByName(String) method.
Tip
Read the following topics for additional information: