Hello,
Trying to catch the 'SortChanging' event.
My first guess is that in GridViewCollectionChangingEventArgs
.NewItems, I'm going to fing the new 'SortDescriptor', and in GridViewCollectionChangingEventArgs
.OldItems
But I see that the behavior is different from what I exepected
Initial state: the gridview is not sorted.
Action : I click on the column titles.
1° Click on columne A : First time, the grid is not sorted, in NewItems, I find one 'new item' corresponding to what expected.
NewItems : A Ascending; [as expected]
OldItems : null; [as expected]
2° I click on the same column again
NewItems : A descending; [as expected]
OldItems : A descending; [not as expected : I expected A Ascending]
3° I click on another column
NewItems : A descending; [not as expected : I expected B something]
OldItems : A descending; [as expected]
(NewItems and OldItems are always = 1.)
Which means that I can when changing sort, I can not distinguinshed what exactly has changed from the EventArgs.
Or am I not doing this the right way ?
Thank you for your help.
And in case here the code I'm using to test it right now:
object o;
SortDescriptor newSortDescriptor, oldSortDescriptor;
string newItemString, oldItemString;
for (int i = 0; i < e.NewItems.Count; i++)
{
o = e.NewItems[i];
if(o.GetType().Equals(typeof(SortDescriptor))) {
newSortDescriptor = (SortDescriptor)o;
newItemString = newSortDescriptor.PropertyName + ' ' + newSortDescriptor.Direction;
}
}
for (int i = 0; i < e.OldItems.Count; i++)
{
o = e.OldItems[i];
if (o.GetType().Equals(typeof(SortDescriptor)))
{
oldSortDescriptor = (SortDescriptor)o;
oldItemString = oldSortDescriptor.PropertyName + ' ' + oldSortDescriptor.Direction;
}
}
Trying to catch the 'SortChanging' event.
My first guess is that in GridViewCollectionChangingEventArgs
.NewItems, I'm going to fing the new 'SortDescriptor', and in GridViewCollectionChangingEventArgs
.OldItems
But I see that the behavior is different from what I exepected
Initial state: the gridview is not sorted.
Action : I click on the column titles.
1° Click on columne A : First time, the grid is not sorted, in NewItems, I find one 'new item' corresponding to what expected.
NewItems : A Ascending; [as expected]
OldItems : null; [as expected]
2° I click on the same column again
NewItems : A descending; [as expected]
OldItems : A descending; [not as expected : I expected A Ascending]
3° I click on another column
NewItems : A descending; [not as expected : I expected B something]
OldItems : A descending; [as expected]
(NewItems and OldItems are always = 1.)
Which means that I can when changing sort, I can not distinguinshed what exactly has changed from the EventArgs.
Or am I not doing this the right way ?
Thank you for your help.
And in case here the code I'm using to test it right now:
object o;
SortDescriptor newSortDescriptor, oldSortDescriptor;
string newItemString, oldItemString;
for (int i = 0; i < e.NewItems.Count; i++)
{
o = e.NewItems[i];
if(o.GetType().Equals(typeof(SortDescriptor))) {
newSortDescriptor = (SortDescriptor)o;
newItemString = newSortDescriptor.PropertyName + ' ' + newSortDescriptor.Direction;
}
}
for (int i = 0; i < e.OldItems.Count; i++)
{
o = e.OldItems[i];
if (o.GetType().Equals(typeof(SortDescriptor)))
{
oldSortDescriptor = (SortDescriptor)o;
oldItemString = oldSortDescriptor.PropertyName + ' ' + oldSortDescriptor.Direction;
}
}