Skip to main content
A newer version of this page is available. .

VGridControl.CustomUnboundData Event

Enables data to be provided to and modified data to be saved from unbound rows.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v18.2.dll

Declaration

public event CustomDataEventHandler CustomUnboundData

Event Data

The CustomUnboundData event's data class is DevExpress.XtraVerticalGrid.Events.CustomDataEventArgs.

Remarks

The CustomUnboundData event is fired for unbound rows only. To create an unbound row, create a row object and set its RowProperties.UnboundType property to an appropriate value, according to the type of data the row is supposed to display. This row’s field name must be unique and it must not refer to any field in the control’s underlying data source.

The CustomUnboundData event is fired in two cases:

  • When the grid is loaded it raises the CustomUnboundData event to populate the unbound rows. 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. Obtain the required value from a custom data source and assign it to the Value parameter.
  • When an unbound row’s data is modified via the grid, the CustomUnboundData event is fired with the IsSetData parameter set to true (consequently the IsGetData parameter is set to false). In this case, you should save the modified data specified by the Value property back to the custom data source.

The currently processed cell is identified by the row and record index. The Row parameter refers to the row. To identify the record, use the ListSourceRowIndex parameter.

Note

If you need to get or set specific cell values while handling the CustomUnboundData event, use methods provided by the bound data source. The event’s ListSourceRowIndex parameter allows you to identify the current data record.

Do not use methods provided by the grid control to get/set cell values (for instance, VGridControlBase.GetCellValue and VGridControlBase.SetCellValue).

Example

Assume that a VGridControl control is bound to the [Order Details] table in the NWind database. The grid contains “Quantity”, “UnitPrice” and “Discount” rows which are bound to the corresponding fields in the database table. The example below shows how to add an unbound row to the grid, to display the amount of each order according to the expression: QuantityUnitPrice(1-Discount).

The result is displayed below:

VGridControl_UnboundRow_ex

using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Rows;
using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.XtraVerticalGrid.Events;

// Unbound row.
EditorRow rowTotal = null;

private void Form1_Load(object sender, EventArgs e) {
    // ...
    vGridControl1.CustomUnboundData += new CustomDataEventHandler(vGridControl1_CustomUnboundData);
    // Create and initialize the unbound Total row.
    rowTotal = new EditorRow();
    rowTotal.Properties.Caption = "Total";
    rowTotal.Properties.FieldName = "Total";
    // Specify format settings.
    rowTotal.Properties.Format.FormatType = FormatType.Numeric;
    rowTotal.Properties.Format.FormatString = "c";            
    rowTotal.Properties.ImageIndex = 1;
    // Disable editing.
    rowTotal.Properties.ReadOnly = true;            
    vGridControl1.Rows.Add(rowTotal);
    rowTotal.Properties.UnboundType = UnboundColumnType.Decimal;
    // Customize the appearance settings.
    rowTotal.Appearance.BackColor = Color.LightYellow;
    rowTotal.Appearance.Font = new System.Drawing.Font(rowTotal.Appearance.Font, 
        System.Drawing.FontStyle.Bold);
}

// Provide data for the Total row.
private void vGridControl1_CustomUnboundData(object sender, CustomDataEventArgs e) {
    VGridControl vGrid = sender as VGridControl;
    if (e.Row == rowTotal && e.IsGetData) {
        DataRowView row = (DataRowView)vGrid.GetRecordObject(e.ListSourceRowIndex);
        decimal unitPrice = Convert.ToDecimal(row["UnitPrice"]);
        decimal quantity = Convert.ToDecimal(row["Quantity"]);
        decimal discount = Convert.ToDecimal(row["Discount"]); ;
        e.Value = unitPrice * quantity * (1 - discount);
    }
}
See Also