Programmatically select multiple items in a DataGrid?

May 29, 2009 at 11:48 AM

I run unit tests on a datagrid, where I select rows by setting the DataGrid.SelectedIndex property.

This works ok.

But I would like to be able to select more  than one row in some tests.  Is that possible?  If so, how do I do it?

Thanx!

 

- Steinar

May 29, 2009 at 12:01 PM

Something like this might do the trick:

   ((DataGridRow)myDataGrid.ItemContainerGenerator.ContainerFromIndex(0)).IsSelected;
   ((DataGridRow)myDataGrid.ItemContainerGenerator.ContainerFromIndex(1)).IsSelected;

May 29, 2009 at 12:24 PM

Or add the underlying objects to the DataGrid.SelectedItems collection.