数据更改时如何保持DataGrid中的选择? [英] How do I maintain selection in a DataGrid when the data changes?

查看:121
本文介绍了数据更改时如何保持DataGrid中的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid,我将DataProvider设置为我的数据。当我的数据更改时,DataGrid会丢失所选行,滚动条将跳回到顶部。如何保持选择和滚动位置?

解决方案

如果您只想保持位置:



在任何功能更改数据时,首先捕获所选索引

  var myidx:int = new int(myDG.selectedIndex); 

和滚动位置

  var myVertPos:int = new int(myDG.verticalScrollPosition); 

运行更改数据的代码,然后执行上述步骤:

  myDG.selectedIndex = myidx; 
myDG.verticalScrollPosition = myVertPos;

哦,你可能想要做一个检查,以确保所选索引没有超过现在在您的DG中的项目长度,如果是,请选择最后一个。在我的经验中,垂直滚动位置大于最大值会导致滚动到最大值


I have a DataGrid and I set the DataProvider to my data. When my data changes the DataGrid loses the selected row and the scroll bar jumps back to the top. How do I maintain the selection and scroll position?

解决方案

If you just want to maintain position:

in whatever function is changing the data, first capture the selected index

var myidx:int = new int(myDG.selectedIndex);

and the scroll position

var myVertPos:int = new int(myDG.verticalScrollPosition);

run the code that changes the data then do the above steps backwards:

myDG.selectedIndex = myidx;
myDG.verticalScrollPosition = myVertPos;

Oh and you will probably want to do a check to make sure that the selected index is not over the length of items now in your DG and select the last one if it is. In my experience setting the vertical scroll position greater than the max just results in scrolling to the max.

这篇关于数据更改时如何保持DataGrid中的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆