windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-5b8a347a.md
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
[DXCategory("Data")]
public event CustomColumnDataEventHandler CustomUnboundColumnData
<DXCategory("Data")>
Public Event CustomUnboundColumnData As CustomColumnDataEventHandler
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 | Gets whether the column/row needs to be populated with cell values. Inherited from UnboundColumnDataEventArgs. |
| IsSetData | Gets whether a cell value changed and data needs to be posted to a data source. Inherited from UnboundColumnDataEventArgs. |
| ListSourceRowIndex | Gets the current row’s index in the data source. |
| Row | Gets the currently processed row. |
| Value | Gets or sets a cell value in an unbound column. Inherited from UnboundColumnDataEventArgs. |
| ValueType | Gets the type of data stored in the unbound column. |
Note
The CustomUnboundColumnData event fires only for visible unbound columns.
The CustomUnboundColumnData event allows you to do the following:
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.
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();
}
}
};
' 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
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.CustomUnboundColumnData event handler.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
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
{
_GridView.CustomUnboundColumnData += _GridView_CustomUnboundColumnData;
}
winforms-grid-tokenedit-in-unbound-column/CS/Form1.cs#L58
gridView.Columns.Add(col);
gridView.CustomUnboundColumnData += OnGridViewCustomUnboundColumnData;
col.ColumnEdit = tokenEditRep;
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
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
Private Sub InitGridView()
AddHandler _GridView.CustomUnboundColumnData, AddressOf _GridView_CustomUnboundColumnData
End Sub
winforms-grid-tokenedit-in-unbound-column/VB/Form1.vb#L55
gridView.Columns.Add(col)
AddHandler gridView.CustomUnboundColumnData, AddressOf OnGridViewCustomUnboundColumnData
col.ColumnEdit = tokenEditRep
winforms-grid-display-icons-in-data-cells/VB/Form1.vb#L157
AddHandler gridView1.CustomDrawCell, AddressOf GridView1_CustomDrawCell
AddHandler gridView1.CustomUnboundColumnData, AddressOf GridView1_CustomUnboundColumnData
Dim checkEdit As RepositoryItemCheckEdit = TryCast(gridControl1.RepositoryItems.Add("CheckEdit"), RepositoryItemCheckEdit)
col.Visible = True
AddHandler gridView1.CustomUnboundColumnData, New DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(AddressOf gridView1_CustomUnboundColumnData)
End Sub
See Also