Retrieve all DataGridRow's from a DataGrid
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.ContainerFromIte开发者_JAVA百科m(item) as DataGridRow;
// Use row...
}
Any way around this?
You can try to scroll each of the items into view before accessing them.
datagrid.ScrollIntoView(item);
I doubt it'll be very fast though if your DataGrid contains many rows
精彩评论