Skip to main content

ColumnView.CustomUnboundColumnData Event

Allows you to supply data to cells in visible unbound columns, and save values entered by users.

Namespace: DevExpress.XtraGrid.Views.Base

Assembly: DevExpress.XtraGrid.v24.1.dll

NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

[DXCategory("Data")]
public event CustomColumnDataEventHandler CustomUnboundColumnData

Event Data

The CustomUnboundColumnData event's data class is CustomColumnDataEventArgs. The following properties provide information specific to this event:

Property Description
Column Gets the unbound column currently being processed.
IsGetData Inherited from UnboundColumnDataEventArgs.
IsSetData Inherited from UnboundColumnDataEventArgs.
ListSourceRowIndex Gets the current row’s index in the data source.
Row Gets the currently processed row.
Value Inherited from UnboundColumnDataEventArgs.
ValueType Gets the type of data stored in the unbound column.

Remarks

Note

The CustomUnboundColumnData event fires only for visible unbound columns.

The CustomUnboundColumnData event allows you to do the following:

  • Populate cells in visible unbound columns with values.
  • Obtain user edits (which you can accept or discard). Read values of the e.IsGetData and e.IsSetData properties to specify a different set of actions for each of these scenarios:

    • e.IsGetData — Returns true when the column needs to be populated and you need to provide cell values.
    • e.IsSetData — Returns true when a user has changed a cell value and you need to save the modified value to a data source.

Read the following topic for additional information and examples: Unbound Columns.

Tip

Use methods provided by the bound data source to get or set cell values within the CustomUnboundColumnData event handler. The e.Row and e.ListSourceRowIndex event parameters identify the processed data row. To get values in a specific row in the data source, use the GetListSourceRowCellValue method or APIs of row objects.

Example

The following example retrieves data from a Dictionary and saves changes back to it:

// Create an unbound column that supports editing.
GridColumn unboundColumn = gridView.Columns.AddField("CustomData");
unboundColumn.UnboundDataType = typeof(string);
unboundColumn.Visible = true;
// Handle the CustomUnboundColumnData event.
Dictionary<int, string> unboundData = new Dictionary<int, string>();
unboundData[1] = "Can live up to 20 years!";
gridView.CustomUnboundColumnData += (sender, e) =>
{
    if(e.Column.FieldName == "CustomData") {
        // Populate columns.
        if(e.IsGetData) {
            if(unboundData.ContainsKey(e.ListSourceRowIndex)) 
                e.Value = unboundData[e.ListSourceRowIndex];
        }
        // Post edits back to the data source.
        if(e.IsSetData && e.Value != null) {
            unboundData[e.ListSourceRowIndex] = e.Value.ToString();
        }
    }
};

Run Demo: How to Edit Unbound Columns View Example: Create & Populate an Unbound Column

Notes

  • The CustomUnboundColumnData event fires for each cell in visible unbound columns. The CustomUnboundColumnData event may fire multiple times for each cell (due to the Grid control’s data processing algorithms). The Grid control does not cache data that you supply within the CustomUnboundColumnData event handler. If these data operations take too long, cache data manually.
  • Do not dispose of the Grid control’s data source, do not modify column settings, the grid’s layout, and the object model within the CustomUnboundColumnData event handler.
  • Server Mode does not support data sorting, grouping, filtering, and summary calculation for unbound columns that get cell values on the CustomUnboundColumnData event. These features are supported for unbound columns that are populated with unbound expressions.

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomUnboundColumnData event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also