Skip to main content

CustomUnboundDataEventArgs Class

Contains data for the CustomUnboundData event.

Namespace: DevExpress.Maui.DataGrid

Assembly: DevExpress.Maui.DataGrid.dll

NuGet Package: DevExpress.Maui.DataGrid

Declaration

public class CustomUnboundDataEventArgs :
    EventArgs

Remarks

The DataGridView.CustomUnboundData event allows you to populate unbound columns with data and save data values modified in unbound columns to the data source. Use the IsGetData and IsSetData properties to determine whether the event handler should provide data or save data from an unbound column.

The Column property returns the currently processed unbound column. To get the data of the processed row or assign a value to any field in this row, use the Item property.

Example

Assume that the DataGridView instance is bound to a collection of orders. An order has the Product.Name, Product.UnitPrice and Quantity fields. This example shows how to add an unbound column (Total) to the grid to calculate each order amount according to the expression: UnitPrice*Quantity.

Implement logic to calculate column values in one of the following ways:

  • Use the GridColumn.UnboundExpression property:

    <dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}">
        <dxg:DataGridView.Columns>
            <dxg:TextColumn FieldName="Product.Name" Caption="Product" Width="170" />
            <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/>
            <dxg:NumberColumn FieldName="Quantity"/>
            <dxg:NumberColumn FieldName="Total" UnboundType="Integer"
                            UnboundExpression="[Quantity] * [Product.UnitPrice]" 
                            IsReadOnly="True" DisplayFormat="C0"/>
        </dxg:DataGridView.Columns>
    </dxg:DataGridView>
    
  • Handle the DataGridView.CustomUnboundData event:

    <dxg:DataGridView x:Name="grid" 
                      ItemsSource="{Binding Orders}" 
                      CustomUnboundData="Grid_CustomUnboundData">
        <dxg:DataGridView.Columns>
            <dxg:TextColumn FieldName="Product.Name" Caption="Product" Width="170" />
            <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/>
            <dxg:NumberColumn FieldName="Quantity"/>
            <dxg:NumberColumn FieldName="Total" UnboundType="Decimal"
                              IsReadOnly="True" DisplayFormat="C0"/>
        </dxg:DataGridView.Columns>
    </dxg:DataGridView>
    
    // Returns the total for a specific row.
    decimal getTotalValue(DataGridView grid, int rowHandle) {
        decimal unitPrice = Convert.ToDecimal(grid.GetCellValue(rowHandle, "Product.UnitPrice"));
        decimal quantity = Convert.ToDecimal(grid.GetCellValue(rowHandle, "Quantity"));
        return unitPrice * quantity;
    }
    
    // Provides data for the Total column.
    void Grid_CustomUnboundData(object sender, CustomUnboundDataEventArgs e) {
        if (e.Column.FieldName == "Total" && e.IsGetData)
            e.Value = getTotalValue((DataGridView)sender, e.SourceIndex);
    }
    

Inheritance

Object
EventArgs
CustomUnboundDataEventArgs
See Also