Click here to Skip to main content
Rate this: bad
good
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)
{
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 28-Aug-12 23:51pm
Edited 11-Sep-12 3:12am
v3
Comments
Thomas Duwe at 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 at 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
good
Please Sign up or sign in to vote.

Solution 2

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

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

  Print Answers RSS
0 Maciej Los 205
1 Richard MacCutchan 185
2 DamithSL 170
3 Tomas Takac 146
4 OriginalGriff 132
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 17 Sep 2012
Copyright © CodeProject, 1999-2014
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