开发者

WPF Toolkit: how to scroll datagrid to show selected item from code behind?

开发者 https://www.devze.com 2022-12-15 17:20 出处:网络
I tried the following, all of which fail on function ScrollIntoView and give a NullRefer开发者_StackOverflow中文版enceException:

I tried the following, all of which fail on function ScrollIntoView and give a NullRefer开发者_StackOverflow中文版enceException:

// doesn't work
grid.SelectedItem = sItem;
grid.ScrollIntoView(sItem);

// doesn't work
grid.SelectedItem = sItem;
grid.Focus();
grid.CurrentColumn = grid.Columns[0];
grid.UpdateLayout();
grid.ScrollIntoView(sItem,grid.Columns[0]);

// doesn't work
grid.SelectedItem = sItem;
grid.UpdateLayout();
grid.ScrollIntoView(sItem);

The problem is, when I select a row from code-behind, selection is not visible - it's somewhere down the bottom. Unless the user scrolls they feels that selection has vanished. I need to scroll a DataGrid to the point that user can see the selection.

I also tried "BringIntoView" as well but no luck.


Try:

grid.SelectedItem = sItem; 
grid.UpdateLayout();
grid.ScrollIntoView(grid.SelectedItem);


Virtualized Stack Panel didn't have an item container, because Item Container does not exist for the item outside the view and that's why this error was shown. Disabling virtualization resolves the issue for now, and the bug has been reported to codeplex toolkit project.

0

精彩评论

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

关注公众号