The requested page is not available for the requested platform. You are viewing the content for Default platform.

DataGridView.CustomUnboundColumnData Event

Enables you to populate unbound columns with data, and save changes that users made in unbound columns.

Namespace: DevExpress.XamarinForms.DataGrid

Assembly: DevExpress.XamarinForms.Grid.dll

Declaration

public event GridColumnDataEventHandler CustomUnboundColumnData

Event Data

The CustomUnboundColumnData event handler receives an argument of the GridColumnDataEventArgs type. The following properties provide information specific to this event.

Property Description
Column Gets the currently processed unbound column.
EditableRowData Gets an object that contains information on the currently processed row and allows you to modify field values.
IsGetData Indicates that you should provide data for the current cell of the unbound column in the event handler.
IsSetData Indicates that you should save the current value of the unbound column's cell to a data source in the event handler.
RowData Gets an object that contains information on the currently processed row.
Source Gets the grid that raised the event.
Value Gets or sets a value of the unbound column's cell.

Remarks

DataGridView allows you to create unbound (calculated) columns. These columns are not bound to any field in the underlying data source. To provide data for these columns, use the GridColumn.UnboundExpression property or handle the CustomUnboundColumnData event. This event fires in two cases:

  • Provide data for unbound columns
    When the grid is loaded, it raises the CustomUnboundColumnData event with the IsGetData parameter set to true (consequently the IsSetData parameter is set to false). In this case, you can supply data for the currently processed cell. Assign the required value to the Value parameter.
  • Save changes
    When a user modifies an unbound column's data, the CustomUnboundColumnData event is fired with the IsSetData parameter set to true (consequently IsGetData is set to false). In this case, you can save the modified data value that the Value parameter returns.

You can identify the currently processed cell by the column (Column) and row (RowData).

Note

The grid raises the CustomUnboundColumnData event only for columns with both the FieldName and UnboundType properties specified.

Examples

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:

<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>
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" CustomUnboundColumnData="Grid_CustomUnboundColumnData">
    <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"
                          IsReadOnly="True" DisplayFormat="C0"/>
    </dxg:DataGridView.Columns>
</dxg:DataGridView>
See Also