windowsforms-devexpress-dot-xtragrid-dot-columns-dot-gridcolumn-230a8987.md
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.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DefaultValue("")]
[DXCategory("Data")]
[XtraSerializableProperty]
public string FieldName { get; set; }
<DXCategory("Data")>
<DefaultValue("")>
<XtraSerializableProperty>
Public Property FieldName As String
| Type | Default | Description |
|---|---|---|
| String | String.Empty |
A String value that specifies the unique column field name. The value is case-sensitive.
|
The FieldName property does not affect the column caption.
Important
FieldName values for unbound columns. Otherwise, the ColumnView.CustomUnboundColumnData event is unable to find required columns.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;
}
};
Dim lengthRuleCondition As New FormatConditionRuleValue()
lengthRuleCondition.Condition = FormatCondition.GreaterOrEqual
lengthRuleCondition.Value1 = 25
lengthRuleCondition.Appearance.BackColor = Color.MediumSeaGreen
lengthRuleCondition.Appearance.Options.UseBackColor = True
Dim lengthRule As New GridFormatRule() With {.Column = gridView.Columns("Length"), .Rule = lengthRuleCondition}
gridView.FormatRules.Add(lengthRule)
AddHandler gridView.RowCellStyle, Sub(s, e)
Dim view As GridView = TryCast(s, GridView)
If view.IsRowSelected(e.RowHandle) AndAlso e.Column.FieldName = "Length" AndAlso lengthRule.IsFit(e.CellValue, view.GetDataSourceRowIndex(e.RowHandle)) Then
Dim ruleAppearance As AppearanceObject = (TryCast(lengthRule.Rule, FormatConditionRuleAppearanceBase)).Appearance
e.Appearance.BackColor = ruleAppearance.BackColor
End If
End Sub
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";
column.FieldName = "ParentProperty.NestedProperty
The following code snippets (auto-collected from DevExpress Examples) contain references to the FieldName property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-reporting-create-grid-based-report/CS/ConvertGridToReportExample/XtraReport1.cs#L45
if (gridColumn.SortOrder == ColumnSortOrder.Ascending)
gField = new GroupField(gridColumn.FieldName, XRColumnSortOrder.Ascending);
else
winforms-grid-show-editor-buttons-on-cell-hover/CS/WindowsApplication3/Form1.cs#L31
if(hi.InRowCell && hi.Column.FieldName == "Text")
rowHandle = hi.RowHandle;
private void gridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) {
if(e.Column.FieldName == ButtonColumnName) {
ISimpleBusinessAction order = gridListEditor.GridView.GetRow(e.RowHandle) as ISimpleBusinessAction;
winforms-grid-display-pictures-from-field-with-image-paths/CS/Form1.cs#L229
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) {
if(e.Column.FieldName == "Image" && e.IsGetData) {
GridView view = sender as GridView;
winforms-custom-buttonedit-display-editvalue-on-button/CS/TestMyButtonEdit/Form1.cs#L37
{
if (e.Column.FieldName == "Info")
e.RepositoryItem = repositoryItemMBE;
winforms-reporting-create-grid-based-report/VB/ConvertGridToReportExample/XtraReport1.vb#L43
If gridColumn.SortOrder = ColumnSortOrder.Ascending Then
gField = New GroupField(gridColumn.FieldName, XRColumnSortOrder.Ascending)
Else
winforms-grid-show-editor-buttons-on-cell-hover/VB/WindowsApplication3/Form1.vb#L33
If hi.InRowCell AndAlso hi.Column.FieldName = "Text" Then
rowHandle = hi.RowHandle
winforms-grid-display-pictures-from-field-with-image-paths/VB/Form1.vb#L218
Private Sub gridView1_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs)
If Equals(e.Column.FieldName, "Image") AndAlso e.IsGetData Then
Dim view As GridView = TryCast(sender, GridView)
winforms-custom-buttonedit-display-editvalue-on-button/VB/TestMyButtonEdit/Form1.vb#L38
Private Sub gridV_CustomRowCellEdit(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs) Handles gridV.CustomRowCellEdit
If e.Column.FieldName = "Info" Then
e.RepositoryItem = repositoryItemMBE
winforms-grid-display-edit-rtf-data/VB/Form1.vb#L49
Private Sub gridView1_CustomRowCellEditForEditing(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs)
If Equals(e.Column.FieldName, "Rich") Then e.RepositoryItem = riPopup
End Sub
See Also