Skip to main content
Tag

ColumnBase.Binding Property

Gets or sets the binding that associates the column with a property in the data source.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

[DefaultValue(null)]
public BindingBase Binding { get; set; }

Property Value

Type Default Description
BindingBase null

The data binding for the column.

Remarks

Use the Binding property to bind columns to data source properties. The data source should implement INotifyPropertyChanged to notify the grid control that a property value has changed.

Set the binding’s Mode property to TwoWay to enable editing.

Note

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

Columns with the specified Binding property work as unbound columns and obtain a field type from the first item. You can use the ColumnBase.UnboundDataType property to specify the field type:

<dxg:GridColumn Binding="{Binding Value, Mode=TwoWay}" UnboundDataType="{x:Type sys:Object}">

The Binding property uses the RowData object as a data context. As a result, the following binding paths are equal:

<dxg:GridColumn FieldName="ProductName1" Binding="{Binding ProductName, Mode=TwoWay}"/>
<dxg:GridColumn FieldName="ProductName2" Binding="{Binding RowData.Row.ProductName, Mode=TwoWay}"/>

Limitations

The following limitations apply when you use the Binding property:

To use the RelativeSource or Source binding, create a ColumnBase.CellTemplate for this column and define the binding within the template.

Refer to the following topic for more information: Binding Columns to Data Source Fields.

Tip

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

When you use the Binding property, the ColumnBase.FieldName property should not contain an existing property name.

Note

Setting the Binding.UpdateSourceTrigger property for the binding passed to the Binding property has no effect. Use the DataViewBase.EnableImmediatePosting to control how the cell values are actually posted.

How the GridControl Identifies Columns

The GridControl identifies columns by their ColumnBase.FieldName values. When you use the Binding property to bind a column to a data field, the GridControl initializes the ColumnBase.FieldName property with a value based on the specified binding expression. If you have multiple columns with the same binding path, set their FieldName to unique values to enable the GridControl to distinguish between columns:

<dxg:GridColumn Binding="{Binding Id, Converter={StaticResource converter1}}" FieldName="c1"/>
<dxg:GridColumn Binding="{Binding Id, Converter={StaticResource converter2}}" FieldName="c2"/>

Example

<dxg:GridControl x:Name="grid">
    <dxg:GridControl.Columns>
        <dxg:GridColumn Header="Id" FieldName="col1" Binding="{Binding Path=Id, Mode=TwoWay}"/>
        <dxg:GridColumn Header="First Name" FieldName="col2" Binding="{Binding Path=FirstName, Mode=TwoWay}"/>
        <dxg:GridColumn Header="Last Name" FieldName="col3" Binding="{Binding Path=LastName, Mode=TwoWay}"/>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TableView Name="view"/>
    </dxg:GridControl.View>
</dxg:GridControl>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Binding 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