Skip to main content

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.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.
EditableRowData Gets an object that contains information on the currently processed row and allows you to modify field values.
IsGetData Gets whether you should provide data for the currently processed cell.
IsSetData Gets whether the current cell’s value should be saved in a data source.
RowData Gets an object that contains information on the currently processed row.
Source Gets the grid control that raised the event.
Value Gets or sets the value of the cell currently being processed.

Remarks

Important

This documentation topic describes legacy technology. We no longer develop new functionality for the GridControl and suggest that you use the new DataGridView control instead.

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.

Example

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;
    }
}
See Also