Colulmn排序条件恢复为WPF中的Save click [英] Colulmn sort criteria is reverting back on Save click in WPF

查看:65
本文介绍了Colulmn排序条件恢复为WPF中的Save click的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我们已经将datagrid与对象列表绑定在一起.用户可以对保留在数据库中的列进行排序,以重新获得新的排序描述,并在新会话中与网格绑定.

但是,单击保存"按钮后,网格将恢复数据中的列排序,并且对保存在数据库中的sortdescription描述没有影响.因此,修改后的sortdescription也无法在成功的会话中检索.

请提出建议.我的数据网格如下所示:-

Hi All

We have datagrid binded with list of object. User can perform sorting on column in it which is persisted to database to retieve new sortdescription back and bind with grid in new session.

But on clicking on Save button the grid is reverting the column sorting from the data and there is no effect on sortdescription saved in database. Hence modified sortdescription is not retrieved in sucessive sessions too.

Please suggest.My datagrid is as shown below :-

CanUserReorderColumns="True" CanUserResizeColumns="True" CanUserResizeRows="True"
CanUserSortColumns="True" AutoGenerateColumns="False" Margin="0,0,0,41"
ItemsSource="{Binding View}" Sorting="_dataGrid1_Sorting">




为保存单击"编写的代码如下所示,其中GetRequiredSortData从被单击的选项卡的数据库中检索所有列的先前排序标准.




Code written for Save click is as shown below where GetRequiredSortData is retrieving previous sortcriteria for all column from database of tab being clicked.

Private void SaveButton_Click(object sender, RoutedEventArgs e)
{
model.Save();

sdRequired = GetRequiredSortData(); 
_dataGrid1.Items.SortDescriptions.Clear();
_dataGrid1.Items.SortDescriptions.Add(new SortDescription("GroupExpandStatus",
ListSortDirection.Descending));
_dataGrid1.Items.Refresh();
ListSortDirection sortDiection;

if (sdRequired != null)
{
sortDiection = ListSortDirection.Descending;
if (sdRequired.SortOrder)
sortDiection = ListSortDirection.Ascending;
_dataGrid1.Items.SortDescriptions.Add(new SortDescription(sdRequired.SortColumn,
sortDiection));
_dataGrid1.Items.Refresh();
} }




现在的问题是,当我们不执行任何操作并单击保存"时,什么也不会更改,并且列仍保持排序状态,但是当修改任何列然后单击保存"时,在这种情况下,所有用户修改或检索到的排序都将撤消.行随机排列.请提出建议.




Now problem is when we dont do anything and click save nothing changes and column remains sorted but when any column is modified and then save is clicked in that case all user modified or retrieved sorting get undone. Row shuffles to random. Please suggest.

推荐答案

Microsoft文档非常具体地说明了要在此处实现的内容:
http://msdn.microsoft.com/en-us/library/0868ft3z.aspx [ ^ ]
The Microsoft documentation is pretty specific on what to implement here:
http://msdn.microsoft.com/en-us/library/0868ft3z.aspx[^]


实际上,在分配给grid时,添加到与grid的itemsource绑定的listviewcollection中的sortingdescription被撤消了,因此我将sortdescriptiondescription绑定到grid之后就应用了它,事情就完成了. :)
谢谢.
Actually sortingdescription added to my listviewcollection binded with itemsource of grid was getting undone when was getting assigned to grid so I applied my sortdescriptions after binding same to grid and things got done. :)
Thanks.


我以异步方法将列表绑定到网格,但在网格中以正常流程应用排序,因此出现了同步问题.因此,仅在列表绑定到网格之后,我才在异步方法中应用了sortingdescriptions.因此,一旦为网格完全分配了列表排序说明中的数据,就可以将其添加到其中.这解决了我的问题.
谢谢.
I was binding my list to grid in async method but was applying sorting in normal flow to grid so there were sync issues. therefore i applied sortingdescriptions in async method only after the list get binded to grid. So once grid is fully assigned data from list sortingdescription get added to it. This resolved my issue.
Thanks.


这篇关于Colulmn排序条件恢复为WPF中的Save click的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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