WPF SelectedItem and Scrolling

I have a DataGrid WPF. DataGrid is bound to IList. The list contains many elements, so the DataGrid MaxHeight is set to a predefined value, and the DataGrid automatically displays the scroll bar. The selection mode and block are set to "single full line".

The form has a button called "New" that adds the item to the list to which the datagrid is bound. After clicking Create, the new item should be the new selected item. I do this through: dataGrid.SelectedItem = newItem;

It works .. but not as good as I expect.

I also want the dataGrid to scroll down to the newly selected item . Any idea on how to do this?

Regards, MadSEB

+5
source share
1 answer

After you set SelectedItem, be sure to call DataGrid.ScrollIntoView with the new item. This will ensure that the new item is displayed on the screen.

+9
source

All Articles