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.