This example illustrates how to process related cells in the Edit Form. This Edit Form contains information about goods. A user can change the Price
value if the CanEdit
checkbox is checked. PositionValue
is the result of Price
and Amount
multiplication. Handle the RowEditStarting event to initialize values in editors when a user starts to edit the row. The CellValueChanging event handler disables the Price
editor depending on the CanEdit
value and calculates PositionValue
.
void OnEditFormCellValueChanging(object sender, CellValueChangedEventArgs e) {
CellValueChangedInEditFormEventArgs editFormArgs = e as CellValueChangedInEditFormEventArgs;
//...
if(e.Cell.Property == nameof(DataItem.CanEdit)) {
var priceData = editFormArgs.CellEditors.FirstOrDefault(x => x.FieldName == nameof(DataItem.Price));
priceData.ReadOnly = !bool.Parse(e.Cell.Value.ToString());
return;
}
if(e.Cell.Property == nameof(DataItem.Price)) {
var positionValueData = editFormArgs.CellEditors.First(d => d.FieldName == nameof(DataItem.PositionValue));
var amountData = editFormArgs.CellEditors.First(d => d.FieldName == nameof(DataItem.Amount));
int price = 0;
int.TryParse((string)e.Value, out price);
positionValueData.Value = (int)amountData.Value * price;
}
}
private void OnRowEditStarting(object sender, RowEditStartingEventArgs e) {
var priceData = e.CellEditors.FirstOrDefault(x => x.FieldName == nameof(DataItem.Price));
var canEditData = e.CellEditors.FirstOrDefault(x => x.FieldName == nameof(DataItem.CanEdit));
priceData.ReadOnly = !(bool)canEditData.Value;
}
Alternatively, you can create commands in a View Model and bind them to the RowEditStartingCommand and CellValueChangingCommand properties.
In the TreeListView, use the following events and properties:
- NodeEditStarting
- TreeListView.CellValueChanging
- NodeEditStartingCommand
- TreeListView.CellValueChangingCommand
- Edit Form
- RowEditStarting / NodeEditStarting
- RowEditStartingCommand / NodeEditStartingCommand
- CellValueChanging / TreeListView.CellValueChanging
- CellValueChangingCommand / TreeListView.CellValueChangingCommand
- Data Grid for WPF - How to Specify Edit Form Settings
- Data Grid for WPF - How to Pause Data Updates in the Edit Form
(you will be redirected to DevExpress.com to submit your response)