WPF DataGrid – Set a cell into edit mode programmatically

datagridwpf

  • I have a WPF DataGrid that shows some data records (bounded to an ObservableCollection).

  • When the user clicks "Edit" button, the currend selected row should move into edit-mode (As if the user double-clicked this row).

How do I do that?

Best Answer

Assuming WPF:

<DataGrid x:Name="dg".... />

Then this code will work:

dg.CurrentCell = new DataGridCellInfo(dg.Items[i], dg.Columns[j]);
dg.BeginEdit();