GridControl.CustomUnboundColumnData Event

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

Namespace: DevExpress.Mobile.DataGrid

Assembly: DevExpress.Mobile.Grid.v18.1.dll

Syntax

public event GridColumnDataEventHandler CustomUnboundColumnData

The event handler receives an argument of the GridColumnDataEventHandler type.

In GridControl, you can create unbound (calculated) columns. These columns are not bound to any field in the underlying data source. Data for these columns can be provided either by creating an expression via the GridColumn.UnboundExpression property or by handling the CustomUnboundColumnData event. This event fires in two cases:

  • Provide Data for Unbound Columns

    When the grid is loaded, it raises the CustomUnboundColumnData event to populate the unbound columns. The event's IsGetData parameter will be set to true (consequently the IsSetData parameter will be set to false). In this case, you need to supply data for the currently processed cell. Assign the required value to the Value parameter.

  • Save Changes

    When an unbound column's data is modified using the grid, the CustomUnboundColumnData event is fired with the IsSetData parameter set to true (consequently the IsGetData parameter is set to false). In this case, you can save the modified data specified by the Value property.

The currently processed cell is identified by the column and row. The GridColumnDataEventArgs.Column parameter refers to the column. To identify the row, use the GridColumnDataEventArgs.RowData event parameter.

Examples

Assume that the GridControl instance is bound to a collection of orders. Each order has the "Product", "UnitPrice"and "Quantity" fields. The example below shows how to add an unbound column to the grid to display the amount of each order according to the expression: UnitPrice*Quantity.

The result is displayed below:

GridControl_CustomUnboundColumnData

// Returns the total for a specific row.
decimal getTotalValue(GridControl 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 OnCustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
    if (e.Column.FieldName == "Total" && e.IsGetData)
        e.Value = getTotalValue (e.Source, e.RowData.RowHandle);
}

// Customizes the appearance settings.
void OnCustomizeCell(CustomizeCellEventArgs e) {
if (e.FieldName == "Total") {
        e.BackgroundColor = Color.FromRgb(247, 240, 213);
        e.Handled = true;
    }
}