tags:

views:

19

answers:

1

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?

A: 

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

Meleak