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.
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;
}
}
[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;
}
}
- Data Grid for WPF - How to Process Related Cells in the Edit Form
- Data Grid for WPF - How to Pause Data Updates in the Edit Form
(you will be redirected to DevExpress.com to submit your response)