14
votes
  • 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?

2
[Found another post that answers this question.][1] Worked for me. [1]: stackoverflow.com/questions/3421597/… - user1007626

2 Answers

9
votes

Assuming WPF:

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

Then this code will work:

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

Here is the documentation of the WPF DataGrid on MSDN. The BeginEdit method seems to be what you are looking for.

PS: I don't know if this is suitable for your application, but many DataGrid users find Single-Click Editing useful.