Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.00/5 (1 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 :-

XAML
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.
C#
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.
Posted
Updated 11-Sep-12 2:12am
v3
Comments
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.

The Microsoft documentation is pretty specific on what to implement here:
http://msdn.microsoft.com/en-us/library/0868ft3z.aspx[^]
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900