开发者

WPF SelectedItem and Scrolling

开发者 https://www.devze.com 2023-01-20 04:29 出处:网络
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 s

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 开发者_Go百科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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消