BeginEdit() not working properly

Sep 25, 2008 at 8:23 PM

I have a grid bound to an observable collection. I have a button that the user clicks to add a new object to the collection (as opposed to setting the CanUserAddRows="True" property). This successfully adds a new row to the grid. What I want to happen is for that row to be selected and then automatically begin editing the first column. Here is the code I have tried (along with several other variations):



Dim newDetailObject As New BusinessObject()







New DataGridCellInfo(newDetailObject, dgDetail.Columns(0)))



The row and cell get selected fine but it never begins editing. I have stepped throw the code in DataGrid and the "CurrentCellContainer" (I think it's called) always returns null. I have even tried setting the dgDetail.CurrentCell property directly, but still no luck. Any other suggestions?


Sep 25, 2008 at 9:42 PM
It is b/c the row container is virtualized.  That is why CurrentCellContainer is null.  For your specific scenario you can do something like dgDetail.ScrollIntoView(newDetailObject) before calling BeginEdit().  This was the example code I used:

            Person p = new Person();
            DataGrid_Standard.CurrentItem = p;
            DataGrid_Standard.CurrentCell = new DataGridCellInfo(p, DataGrid_Standard.Columns[0]);

Sep 26, 2008 at 2:25 PM
Using your code the row successfully scrolls into view (which I wasn't doing previosly) and the cell is visibly selected, but BeginEdit() still does not work. "CurrentCellContainer" is still returning null, and the editing doesn't start unless I double click the cell. Any other suggestions?

Sep 26, 2008 at 2:28 PM
I fixed it. I needed to make sure the grid had focus prior to call BeginEdit().