Datagrid row or cell returning null reference

Aug 24, 2009 at 5:57 AM

I have a tab menu and each tabitem contains a toolkit datagrid. I want to change the datagrid cell color if that cell is edited and retain the changed color even if the selected row or tab is changed. I was able to retain the changed color for selected row changed.

DataGridRow row = (DataGridRow)DataGrid.ItemContainerGenerator.ContainerFromIndex(index) and passing this row to the Datagrid.Columns[index].GetCellContents(row).

But the problem is this seems to work only for the first time when the datagrid is assigned to the observable collection and on the subsequent tab changes or refreshing datagrid, above code is returning null for the row object. I have also tried this VisualTreeHelper and finding child of the datagrid but it is also returning null for the second time.For the first run both the approaches works smoothly.

Aug 25, 2009 at 6:27 AM

Are you certain that the DataGrid is populated at that point? I could be wrong, but recall seeing someone posting about a very similar setup not too long ago and their problem was that the DataGrid was being reset when the user changed tabs. Maybe something similar is happening here?