New Row has wrong focus and wrong children

Nov 23, 2008 at 4:01 AM

I have two problems when a new row is added to the DataTable which is bound to the DataGrid.: 1. Focus is not on the new row and 2. The children do not get notified of updates.

Problem 1.  When the new row is added, it gets placed in its proper sorted position. The focus, however, is not on the new row but on the row following the new row. I tried to change the focus to the new row in the DataTable's RowChanged event, but the DataGrid changed it back. I guess it’s running after my code. Any suggestion on how to get around this?

Problem 2. I have a column that displays one of the DataTable's children using a ListBox. This ListBox gets updated whenever the row's array of children changes even when the row has no children to begin with. That is, it works except for newly added rows. I'm guessing that when a new row is still detached from the DataTable it is not allowed to have any children and gets a dummy array and then when it is finally added, it gets its official array that receive notifications of changes. Refreshing the DataTable does fix the problem. But this can get expensive as the size of the DataTable grows. Any suggestions on how to get around this?

 

Coordinator
Dec 5, 2008 at 12:42 PM
For problem 1 you can listen to the RowEditEnding event and use a dispatcher.BeginInvoke to delay execution until after the editing occurs.  In the delegate you can then change row selection back to the bottom.