I have a DataGrid
where the SelectedItem
is bound to a VM Selected property. I have a search control that will do a find and the SelectedItem
of the DataGrid
changes (and scrolls into view). WPF 4.0 and DataGrid
SelectionUnit="FullRow"
.
My problem is with the focus. The DataGrid
receives focus (via attached property / binding) but you can't use the Up, Down, Page Up, Page Down keys to change rows (SelectedItem
). If I tab again, the first cell of the first row displayed is selected which changes the SelectedItem
.
Bottom line, how can I give keyboard focus to the DataGridCell
for the SelectedItem
when the DataGrid
receives focus?
There are so many DataGrid
/ Focus
questions and tried a few things already. Thanks for your help.
This PowerShell snippet worked for me:
You need to give the newly selected row logical focus. After selecting the new item try replacing your
SetFocus
call with this:The FocusManager solution didn't work for me for some reason. Also I required a more general apporach. So here is, what I came up with:
And call it like this: