How do I use the Datagrid.SelectedItem
to select a row programmatically?
Do I first have to create a IEnumerable
of DataGridRow
I came across this fairly recent (compared to the age of the question) TechNet article that includes some of the best techniques I could find on the topic:
WPF: Programmatically Selecting and Focusing a Row or Cell in a DataGrid
It includes details that should cover most requirements. It is important to remember that if you specify custom templates for the DataGridRow for some rows that these won't have DataGridCells inside and then the normal selection mechanisms of the grid doesn't work.
You'll need to be more specific on what datasource you've given the grid to answer the first part of your question, as the others have stated.