How Do You Set The Selected Rows In A WPF Datagrid

Mar 20, 2009 at 2:25 PM
I am looking for an example on how to set a row as selected in a WPF datagrid.  I  have tried traversing the Visual Tree but I am hoping there is an easier way.  In my last post I received an answer that showed how to retrieve the currently selected indexes without using the Visual Tree.  I am hoping there is also a way to set the selected rows without using the Visual Tree.

Any help would be greatly appreciated.

Mar 23, 2009 at 8:41 AM
SelectedItems is a read/write collection, so you can iterate through Items to find the items you want (based on whatever criteria) and add them to DataGrid.SelectedItems.

In general, unless you are actually interested in programmatically finding a specific object in the visual tree, you almost never need to navigate the visual tree itself.
Mar 23, 2009 at 2:18 PM
Awesome thanks for your help!  That worked perfectly.