Skip to main content

GridControl.CustomUnboundColumnData Event

Allows you to populate unbound columns with data.

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

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.

Note

The GridControl does not raise the CustomUnboundColumnData event if you use the TreeList View. Handle the TreeListView.CustomUnboundColumnData event instead.

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 CustomUnboundColumnData event.

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