DevExpress-Examples / wpf-data-grid-edit-form-related-cells

Process related cells in the Edit Form.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Data Grid for WPF - How to Process Related Cells in the Edit Form

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:

Files to Look At

Code-Behind

MVVM Pattern

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Process related cells in the Edit Form.

License:Other


Languages

Language:C# 50.9%Language:Visual Basic .NET 49.1%