Claudio Ghiggia

Claudio Ghiggia

  • NA
  • 3
  • 4.3k

UpArrow/DownArrow keys in WPF DataGrid

Sep 29 2012 5:53 AM

I have a problem concerning the WPF DataGrdid and the behaviour of the UpArrow and DownArrow keys.

As long as I click the mouse on a row (thus automatically setting the SelectedItem and SelectedIndex properties) and then press UpArrow/DwnArrow keys everything's fine: the lightbar moves upwards or downwards according to the keys.
If I programmatically set the SelectedIndex or SelectedItem to a different row, then the UpArrow/DownArrow keys show this odd behaviour:
DownArrow: the first keypress doesn't move the lightbar and, regardless of the SelectedIndex, a bold border appears around a cell on the first row of the page (sometimes after some scrolling of the rows); the second keypress brings the lightbar to the second row of the page.
UpArrow: (behaviour similar to the previous one) the first keypress always shows a bold border around a cell on the last row of the page and the second keypress brings the lightbar to the last but one row.
In both cases the behaviour always becomes regular from the third keypress.

Can anybody tell me how to solve this problem?
Thank you very much in advance!


Answers (2)