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?
By default, you can edit items directly in the DataGrid. The user can enter edit mode in a cell by pressing F2 key or double tapping on a cell. Alternatively, you can set the DataGridColumn. IsReadOnly property to true to disable editing in specific columns of the DataGrid.
By default, users can edit the contents of the current DataGridView text box cell by typing in it or pressing F2. This puts the cell in edit mode if all of the following conditions are met: The underlying data source supports editing. The DataGridView control is enabled.
A Grid is a control for laying out other controls on the form (or page). A DataGrid is a control for displaying tabular data as read from a database for example.
WPF DataGrid (SfDataGrid) provides built-in row called AddNewRow. It allows user to add a new row to underlying collection. You can enable or disable by setting SfDataGrid.
Assuming WPF:
<DataGrid x:Name="dg".... />
Then this code will work:
dg.CurrentCell = new DataGridCellInfo(dg.Items[i], dg.Columns[j]);
dg.BeginEdit();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With