I’m trying to get a hold of all DataGridRows for a DataGrid, don’t ask me why 🙂
The DataGrid is bound to a DataView and I’m using this code but it failes after some rows.. I guess that they haven’t been created yet.
foreach (DataRowView item in datagrid.Items)
{
// Sometimes row == null...
DataGridRow row = dataGrid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
// Use row...
}
Any way around this?
You can try to scroll each of the items into view before accessing them.
I doubt it’ll be very fast though if your DataGrid contains many rows