Search code examples
c#wpfdatagridcollectionviewsourcelostfocus

WPF Datagrid lost focus when refresh my collection


When key press "F5"

I refresh my collection colecao.View.Refresh();

...and lost focus of my datagrid

To back focus in row of datagrid I try this:

  1. Focus() on datagrid
  2. FocusManager.SetFocusedElement
  3. row.Focus()
  4. ......

Solution

  • If your using a CollectionView, I think you have to move the current selection using view.MoveCurrentTo(object) or similar function.

    Here you can find others, like view.MoveCurrentToFirst(), etc.