GridControl.CustomUnboundColumnData Event

Allows you to populate unbound columns with data.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v21.2.dll

Declaration

public event GridColumnDataEventHandler CustomUnboundColumnData

Event Data

The CustomUnboundColumnData event's data class is GridColumnDataEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the unbound column currently being processed.
IsGetData Gets whether you should provide data for the currently processed cell. Inherited from ColumnDataEventArgsBase.
IsSetData Gets whether a cell’s value should be saved to a data source. Inherited from ColumnDataEventArgsBase.
ListSourceRowIndex Gets the index of the record in a data source to which the processed row corresponds.
Source Gets the grid control that raised the event.
Value Gets or sets the processed cell’s value. Inherited from ColumnDataEventArgsBase.

The event data class exposes the following methods:

Method Description
GetListSourceFieldValue(Int32, String) Returns the value of the specified cell within the specified row in the grid’s data source.
GetListSourceFieldValue(String) Returns the value of the specified cell within the processed row in the grid’s data source.

Remarks

Unbound Columns are not bound to any field in the data source. You can calculate unbound column values based on values of bound columns or populate unbound columns with data from a custom data source.

Handle the CustomUnboundColumnData event to populate unbound columns with data and save changes to a custom data source.

Display Unbound Data
The GridColumnDataEventArgs.IsGetData property returns true when the GridControl populates unbound columns with data. The GridColumnDataEventArgs.ListSourceRowIndex property returns the processed row’s index in a grid’s data source. Specify the GridColumnDataEventArgs.Value property to display data in the unbound column.
Save Changes
The GridColumnDataEventArgs.IsSetData property returns true when a user changes a cell value. The GridColumnDataEventArgs.Value property returns the modified cell value that you can save to a custom data source.

If you want to maintain a clean MVVM pattern and populate unbound columns with data in a View Model, create a command and bind it to the CustomUnboundColumnDataCommand property.

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:GridControl.Columns>
        <dxg:GridColumn FieldName="ProductName" />
        <dxg:GridColumn FieldName="UnitPrice">
            <dxg:GridColumn.EditSettings>
                <dxe:TextEditSettings DisplayFormat="c2" />
            </dxg:GridColumn.EditSettings>
        </dxg:GridColumn>
        <dxg:GridColumn FieldName="UnitsOnOrder" />
        <dxg:GridColumn FieldName="Total" UnboundType="Boolean" ReadOnly="True">
            <dxg:GridColumn.EditSettings>
                <dxe:TextEditSettings DisplayFormat="c2" />
            </dxg:GridColumn.EditSettings>
        </dxg:GridColumn>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>
private void grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
    if(e.IsGetData) {
        int price = Convert.ToInt32(e.GetListSourceFieldValue("UnitPrice"));
        int unitsOnOrder = Convert.ToInt32(e.GetListSourceFieldValue("UnitsOnOrder"));
        e.Value = price * unitsOnOrder;
    }
}
See Also