Back to Devexpress

ColumnView.CustomUnboundColumnData Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-5b8a347a.md

latest11.7 KB
Original Source

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.v25.2.dll

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

Declaration

csharp
[DXCategory("Data")]
public event CustomColumnDataEventHandler CustomUnboundColumnData
vb
<DXCategory("Data")>
Public Event CustomUnboundColumnData As CustomColumnDataEventHandler

Event Data

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

PropertyDescription
ColumnGets the unbound column currently being processed.
IsGetDataGets whether the column/row needs to be populated with cell values. Inherited from UnboundColumnDataEventArgs.
IsSetDataGets whether a cell value changed and data needs to be posted to a data source. Inherited from UnboundColumnDataEventArgs.
ListSourceRowIndexGets the current row’s index in the data source.
RowGets the currently processed row.
ValueGets or sets a cell value in an unbound column. Inherited from UnboundColumnDataEventArgs.
ValueTypeGets 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:

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:

csharp
// 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();
        }
    }
};
vb
' Create an unbound column that supports editing.
Dim unboundColumn As GridColumn = gridView.Columns.AddField("CustomData")
unboundColumn.UnboundDataType = GetType(String)
unboundColumn.Visible = True
' Handle the CustomUnboundColumnData event.
Dim unboundData As New Dictionary(Of Integer, String)()
unboundData(1) = "Can live up to 20 years!"
AddHandler gridView.CustomUnboundColumnData, Sub(sender, e)
    If e.Column.FieldName = "CustomData" Then
        ' Populate columns.
        If e.IsGetData Then
            If unboundData.ContainsKey(e.ListSourceRowIndex) Then
                e.Value = unboundData(e.ListSourceRowIndex)
            End If
        End If
        ' Post edits back to the data source.
        If e.IsSetData AndAlso e.Value IsNot Nothing Then
            unboundData(e.ListSourceRowIndex) = e.Value.ToString()
        End If
    End If
End Sub

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.

winforms-grid-multiple-row-selection-web-style-checkboxes/CS/E1271/CheckMarkSelection.cs#L132

csharp
view.CustomDrawGroupRow += new RowObjectCustomDrawEventHandler(View_CustomDrawGroupRow);
view.CustomUnboundColumnData += new CustomColumnDataEventHandler(view_CustomUnboundColumnData);
view.KeyDown += new KeyEventHandler(view_KeyDown);

winforms-grid-add-radio-group-column/CS/Helper/GridRadioGroupColumnHelper.cs#L69

csharp
{
    _GridView.CustomUnboundColumnData += _GridView_CustomUnboundColumnData;
}

winforms-grid-tokenedit-in-unbound-column/CS/Form1.cs#L58

csharp
gridView.Columns.Add(col);
gridView.CustomUnboundColumnData += OnGridViewCustomUnboundColumnData;
col.ColumnEdit = tokenEditRep;

winforms-grid-display-summary-calculated-over-detail-rows-in-master-row/CS/WindowsApplication59/Form1.cs#L26

csharp
col.Visible = true;
    gridView1.CustomUnboundColumnData+=new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(gridView1_CustomUnboundColumnData);
}

winforms-grid-multiple-row-selection-web-style-checkboxes/VB/E1271/CheckMarkSelection.vb#L160

vb
AddHandler view.CustomDrawGroupRow, New RowObjectCustomDrawEventHandler(AddressOf View_CustomDrawGroupRow)
AddHandler view.CustomUnboundColumnData, New CustomColumnDataEventHandler(AddressOf view_CustomUnboundColumnData)
AddHandler view.KeyDown, New KeyEventHandler(AddressOf view_KeyDown)

winforms-grid-add-radio-group-column/VB/Helper/GridRadioGroupColumnHelper.vb#L70

vb
Private Sub InitGridView()
    AddHandler _GridView.CustomUnboundColumnData, AddressOf _GridView_CustomUnboundColumnData
End Sub

winforms-grid-tokenedit-in-unbound-column/VB/Form1.vb#L55

vb
gridView.Columns.Add(col)
AddHandler gridView.CustomUnboundColumnData, AddressOf OnGridViewCustomUnboundColumnData
col.ColumnEdit = tokenEditRep

winforms-grid-display-icons-in-data-cells/VB/Form1.vb#L157

vb
AddHandler gridView1.CustomDrawCell, AddressOf GridView1_CustomDrawCell
AddHandler gridView1.CustomUnboundColumnData, AddressOf GridView1_CustomUnboundColumnData
Dim checkEdit As RepositoryItemCheckEdit = TryCast(gridControl1.RepositoryItems.Add("CheckEdit"), RepositoryItemCheckEdit)

winforms-grid-display-summary-calculated-over-detail-rows-in-master-row/VB/WindowsApplication59/Form1.vb#L22

vb
col.Visible = True
    AddHandler gridView1.CustomUnboundColumnData, New DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(AddressOf gridView1_CustomUnboundColumnData)
End Sub

See Also

UnboundDataType

Unbound Columns

ColumnView Class

ColumnView Members

DevExpress.XtraGrid.Views.Base Namespace