WPF Datagrid set selected row

后端 未结 8 1352
无人共我
无人共我 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:54

    If anyone stumblng here has problems with internal grid selection happening after OnSelectionChanged - after unsuccessfully trying out all the selection setters for a dozen hours the only thing that worked for me was reloading and repopulating DataGrid along with selected item. Not elegant at all, but at this point I'm not sure if a better solution exists in my situation.

    datagrid.ItemsSource = null
    datagrid.ItemsSource = items;
    datagrid.SelectedItem = selectedItem;
    

提交回复
热议问题