Skip to content

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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)