problems about DataGrid.ItemContainerGenerator.ContainerFromIndex(int index)

Sep 12, 2008 at 4:19 AM
when I want to get a row from the datagrid using the following code:

DataGridRow row ;
for (int i = 0; i < DataGrid_Standard.Items.Count; i++)
      row = (DataGridRow)DataGrid_Standard.ItemContainerGenerator.ContainerFromIndex(i);

The value of  DataGrid_Standard.Items.Count is 41, but when i>25, the row will get null value.

And there is another same problem:

List<object> _Source = (List<object>)bizDataGridView1.DataContext;
for (int i = 0; i< _Source.Count - 1; i++)
              CheckBox _CheckBox = (CheckBox)bizDataGridView1.Columns[0].GetCellContent(bizDataGridView1.Items[i]);

The value of  _Source.Count is 81, when i>17,  _CheckBox will get a null.

There is a bug with DataGrid?
Sep 12, 2008 at 1:24 PM
What you are experiencing is item container virtualization.  Take a look at the implementation of GetRow and GetCell in this thread,  Both methods deal with virtualization by scrolling the item container into view.