WPF Datagrid set selected row

后端 未结 8 1336
无人共我
无人共我 2020-11-27 05:08

How do I use the Datagrid.SelectedItem to select a row programmatically?

Do I first have to create a IEnumerable of DataGridRow

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 05:32

    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.

提交回复
热议问题