On WPF DataGrid, how to programmatically put a cell into edit mode?
Okay, I have a WPF DataGrid which is bound to an Observable Collection of data objects. It's a 2-way binding. I have an "Add" button that adds a data row to the underlying list, scrolls to that item in the DataGrid, and selects that row. All that works perfectly. The UI shows an empty row added to the end of the DataGrid, and that row is selected. However, the user has to click the first cell in order to edit it, which isn't ideal.
:mad:
Once I've gotten this far, how do I tell it to open the first cell into edit mode? I tried the obvious, dataGrid.BeginEdit(), but it didn't do anything that I can see. Still have to click the cell to put it in edit mode. I also tried some solutions culled from online, using the visual tree to select a cell, but that didn't work, either... the cell always came back null.
I have the DataGrid.SelectionUnit set to FullRow, and the SelectionMode set to Extended. I cannot set the SelectionUnit to Cell, because there are several scenarios the user will want to select multiple rows.
So, any idea how to set a column to edit mode from the code-behind?
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Try something like this: (adapt to your own controls).
Code:
PlantasDataGridView.Rows(0).Cells(1).Selected = True
PlantasDataGridView.Focus()
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Sorry, typed that last example without testing it. This one works:
Code:
PlantasDataGridView.CurrentCell = PlantasDataGridView.Rows(0).Cells(1)
PlantasDataGridView.Focus()
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Hmmm... that looks like it's for a DataGridView control. I'm using a DataGrid control. I do not believe this code will work on a DataGrid, but I'll try it first thing in the morning.
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Confirmed. This is a solution that might work with DataGridView but not with DataGrid.
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?
Yeah, sorry. Did not pay close attention to that.
Re: On WPF DataGrid, how to programmatically put a cell into edit mode?