wpf datagrid排序时无法执行Up-down操作
嗨,
我有一个数据网格(来自 wpf 工具包),它绑定到一个可观察集合。有两个按钮“向上”和“向下”,可相应移动所选行。 例如:如果数据网格中有 10 个项目,并且如果我选择第 4 个项目并按“向上”箭头,则第 4 个项目将移动到第 3 个项目,而前一个第 3 个项目将是第 4 个项目。即与前一个项目交换。同样,“向下”箭头的方向也相反。
private void BtnUpArrowClick(对象发送者, RoutedEventArgs e) {
try
{
btnDownArrow.IsEnabled = true;
currentRow = grdSeqData.SelectedIndex;
if (currentRow == 0)
{
btnUpArrow.IsEnabled = false;
}
else
{
upRow = currentRow - 1;
if (upRow >= 0)
{
sequenceDataList.Move(currentRow, upRow);
currentRow = upRow;
}
else
{
btnUpArrow.IsEnabled = false;
}
}
}
catch (Exception ex)
{
CatchExeption(LanguageHandler.GetCurrentCultureText("EventUpArrow_Exception"), ex);
}
}
当数据网格未排序时,上面的代码可以正常工作。当我通过标题单击对数据网格进行排序,然后执行“向上”或“向下”操作时,数据网格中没有任何反映。
视图正在排序,因为我的绑定集合保持不变。所以我试图将收藏品从视图中移走,但徒劳无功。
ICollectionView 视图 = CollectionViewSource.GetDefaultView(grdSeqData.ItemsSource) as ListCollectionView; view.MoveCurrentToNext();
我认为当应用数据网格排序描述时,视图将不会相应移动。请帮忙。
HI,
I have a datagrid (from wpf toolkit) which is binded to an observable collection . There are two buttons "Up" and "Down" which moves the selected row accordingly.
For eg: If there are 10 items in the datagrid and if I select the 4th item and press "Up" arrow ,then the 4th item will be moved to 3rd item and previous 3rd item will be 4th item. ie swapping with previous item. Similarly "Down" arrow the other way.
private void BtnUpArrowClick(object sender, RoutedEventArgs e)
{
try
{
btnDownArrow.IsEnabled = true;
currentRow = grdSeqData.SelectedIndex;
if (currentRow == 0)
{
btnUpArrow.IsEnabled = false;
}
else
{
upRow = currentRow - 1;
if (upRow >= 0)
{
sequenceDataList.Move(currentRow, upRow);
currentRow = upRow;
}
else
{
btnUpArrow.IsEnabled = false;
}
}
}
catch (Exception ex)
{
CatchExeption(LanguageHandler.GetCurrentCultureText("EventUpArrow_Exception"), ex);
}
}
The above code work fine when the datagrid is not sorted. When i sort the datagrid via header click, and then do the "Up" or "Down" operation nothing is reflected in the datagrid.
The view is getting sorted where as my binded collection remains the same. So i tried to move the collection from view but in vain.
ICollectionView view = CollectionViewSource.GetDefaultView(grdSeqData.ItemsSource) as ListCollectionView;
view.MoveCurrentToNext();
I think when the datagrid sortdescription is applied, then the view will not move accordingly. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论