/wpf-data-grid-specify-edit-form-settings

Specify Edit Form settings in the Data Grid.

Primary LanguageVisual Basic .NETOtherNOASSERTION

Data Grid for WPF - How to Specify Edit Form Settings

This example illustrates how to specify Edit Form settings when a user starts to edit a row. To initialize values or make certain editors read-only, handle the RowEditStarting / NodeEditStarting event or create a command in a View Model and bind it to the RowEditStartingCommand / NodeEditStartingCommand property. The event / command arguments contain the CellEditors property that returns an array of CellEditorData objects. Each object allows you to specify the corresponding editor's settings.

The GridControl contains information about employees. The following code sample initializes the ID editor (CellEditors[0] in code) and disables the Department editor (CellEditors[4]) for new rows.

Code-Behind

private void OnRowEditStarting(object sender, RowEditStartingEventArgs e) {
    if(Equals(e.RowHandle, DataControlBase.NewItemRowHandle)) {
        e.CellEditors[0].Value = grid.VisibleRowCount + 1;
        e.CellEditors[4].ReadOnly = true;

    } else {
        e.CellEditors[0].ReadOnly = true;
        e.CellEditors[4].ReadOnly = false;
    }
}

MVVM Pattern

[Command]
public void OnRowEditStarting(RowEditStartingArgs args) {
    if(args.IsNewItem) {
        args.CellEditors[0].Value = Employees.Count + 1;
        args.CellEditors[4].ReadOnly = true;

    } else {
        args.CellEditors[0].ReadOnly = true;
        args.CellEditors[4].ReadOnly = false;
    }
}

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)