Skip to main content
Tag

ColumnBase.FieldName Property

Gets or sets the name of the database field assigned to this column. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v23.2.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

[DefaultValue("")]
public virtual string FieldName { get; set; }

Property Value

Type Default Description
String String.Empty

A String value that specifies the name of a data field.

Remarks

Use the FieldName property to bind columns to data source properties.

Note

When you use a custom CellTemplate, follow the recommendations below to automatically bind cell values to the property specified by FieldName:

When you use the ColumnBase.Binding property to bind a column to a data field, the GridControl initializes the FieldName property with a value based on the specified binding expression.

If your field name has a complex path (like “ClientClasses.Count“) and you want the GridControl to reflect changes made in these nested properties, set the DataControlBase.DetectNestedPropertyChanges property to true.

Important

When working with data structures that contain Dynamic Objects, use the ColumnBase.Binding property instead of FieldName.

Do not bind multiple columns to the same field in the data base. Only a single column can be bound to a specific field in the database. If you need to create another column bound to the same field, create a new unbound column, and set its FieldName property to a unique string. Then, handle the GridControl.CustomUnboundColumnData event to populate this column with the same data as the first column.

Example

This example shows how to add an unbound column to the GridControl. This column should display the total price, calculated as follows: UnitPrice * UnitsOnOrder.

DevExpress WPF | Grid Control - Custom Unbound Data

View Example: How to Create Unbound Columns

<dxg:GridControl x:Name="grid"
                 CustomUnboundColumnData="grid_CustomUnboundColumnData">
    <dxg:GridColumn FieldName="CompanyName"/>
    <dxg:GridColumn FieldName="City"/>
    <dxg:GridColumn FieldName="UnitPrice">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridColumn FieldName="Quantity"/>
    <dxg:GridColumn FieldName="Total" UnboundDataType="{x:Type sys:Decimal}" ReadOnly="True">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>
void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
    if(e.IsGetData) {
        int price = Convert.ToInt32(e.GetListSourceFieldValue(nameof(Product.UnitPrice)));
        int quantity = Convert.ToInt32(e.GetListSourceFieldValue(nameof(Product.Quantity)));
        e.Value = price * quantity;
    }
}

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.

See Also