Click here to Skip to main content
13,146,315 members (43,084 online)
Rate this:
Please Sign up or sign in to vote.
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">

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)
sdRequired = GetRequiredSortData(); 
_dataGrid1.Items.SortDescriptions.Add(new SortDescription("GroupExpandStatus",
ListSortDirection sortDiection;
if (sdRequired != null)
sortDiection = ListSortDirection.Descending;
if (sdRequired.SortOrder)
sortDiection = ListSortDirection.Ascending;
_dataGrid1.Items.SortDescriptions.Add(new SortDescription(sdRequired.SortColumn,
} }

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.
Posted 28-Aug-12 22:51pm
Updated 11-Sep-12 2:12am
Thomas Duwe 29-Aug-12 6:08am
You have to be a little more specific.

What datagrid are you using?
How is the list of data bound to the grid?
What's happening in your save method?

Some code would be really helpful, otherwise nobody can help you.
Kenneth Haugland 11-Sep-12 8:15am
Use have a comment or question when you have some comments to an individual, and use imnprove question when you have additional information or updated code. The solution is for solutions only.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The Microsoft documentation is pretty specific on what to implement here:[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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. :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100