Skip to main content

GridColumn.FieldName Property

To bind a column to a data source field, set this property to the required data field name. To create unbound columns, assign a unique identifier to this property. If you obtained a column as a method return value or as an event argument, read the FieldName property value to identify this column.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v23.1.dll

NuGet Package: DevExpress.Win.Grid

Declaration

[DefaultValue("")]
[DXCategory("Data")]
[XtraSerializableProperty]
public string FieldName { get; set; }

Property Value

Type Default Description
String String.Empty

A String value that specifies the unique column field name. The value is case-sensitive.

Remarks

The FieldName property does not affect the column caption.

Important

  • Assign unique FieldName values for unbound columns. Otherwise, the ColumnView.CustomUnboundColumnData event is unable to find required columns.
  • For data-bound records, it is not recommended to bind multiple columns to the same data field because it limits and/or alters Data Grid functionality: you cannot access a specific column by field name, an update to a single cell value affects all related columns, unexpected behavior when records are sorted, filtered or grouped, etc.

The following sample shows how to obtain a column by its FieldName and change the column’s appearance. To test this code sample, run the following Demo Center module: Prioritize conditional formatting appearances.

FormatConditionRuleValue lengthRuleCondition = new FormatConditionRuleValue();
lengthRuleCondition.Condition = FormatCondition.GreaterOrEqual;
lengthRuleCondition.Value1 = 25;
lengthRuleCondition.Appearance.BackColor = Color.MediumSeaGreen;
lengthRuleCondition.Appearance.Options.UseBackColor = true;
GridFormatRule lengthRule = new GridFormatRule() { Column = gridView.Columns["Length"], Rule = lengthRuleCondition };
gridView.FormatRules.Add(lengthRule);

gridView.RowCellStyle += (s, e) => {
    GridView view = s as GridView;
    if (view.IsRowSelected(e.RowHandle) &&
        e.Column.FieldName == "Length" &&
        lengthRule.IsFit(e.CellValue, view.GetDataSourceRowIndex(e.RowHandle)))
    {
        AppearanceObject ruleAppearance = (lengthRule.Rule as FormatConditionRuleAppearanceBase).Appearance;
        e.Appearance.BackColor = ruleAppearance.BackColor;
    }
};

Bind Grid Columns to Nested Properties

You can also bind a column to a nested property. To do this, assign parent and child property names (separated by the dot character - “.”) to the FieldName property.

column.FieldName = "ParentProperty.NestedProperty";
See Also