The Data Grid's edit form displays a combo box editor for a DxDataGridComboBoxColumn
. When you bind this column to a collection of custom objects, the combo box editor is populated with items that correspond to these custom objects. The ValueFieldName
property specifies a custom object's field, which provides item values. These item values match cell values in the Data Grid's data source.
Razor<DxDataGrid Data="@GridDataSource"
RowUpdating="@((dataItem, newValues) => OnRowUpdating(dataItem, newValues))" ...>
<DxDataGridComboBoxColumn Field="@nameof(GridDataSource.RegionID)"
Data="@ShipRegions"
ValueFieldName="@nameof(ShipRegion.ID)" ...>
</DxDataGridComboBoxColumn>
...
</DxDataGrid>
@code {
IEnumerable<GridDataItem> GridDataSource;
IEnumerable<ShipRegion> ShipRegions;
...
void OnRowUpdating(GridDataItem dataItem, Dictionary<string, object> newValue)
{
MyDataService.Update(dataItem, newValue);
}
}
In previous versions, the RowUpdating
, RowUpdatingAsync
, RowInserting
and RowInsertingAsync
event handlers contained a value of the combo box's selected item in the dictionary of new values.
In v19.2, these event handlers contain the combo box's selected item (the entire custom object). This allows you not only to operate with the selected item's value, but access values of all its fields.
If you handled one of these events, update your code that posts changes to the data source. You should now access an item value from the custom object as shown in the code snippet below.
Old
C#void Update(GridDataItem dataItem, IDictionary<string, object> newValue) {
foreach (var field in newValue.Keys) {
switch (field) {
...
case nameof(dataItem.RegionID):
dataItem.RegionID = (string)newValue[field];
break;
}
}
}
New
C#void Update(GridDataItem dataItem, IDictionary<string, object> newValue) {
foreach (var field in newValue.Keys) {
switch (field) {
...
case nameof(dataItem.RegionID):
dataItem.RegionID = ((ShipRegion)newValue[field]).ID;
break;
}
}
}