Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF SelectedItem and Scrolling

I have a WPF DataGrid. The DataGrid is bound to an IList. The list has many many items so the DataGrid MaxHeight is set to a predefined value and the DataGrid automatically displays a scroll bar. The selection mode and unit are set to "single full row".

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

This works ..but not as well as I expect it to.

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

Regards, MadSEB

like image 824
MadSeb Avatar asked Oct 12 '10 19:10

MadSeb


1 Answers

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

like image 118
Reed Copsey Avatar answered Oct 05 '22 00:10

Reed Copsey