This is a migrated thread and some comments may be shown as answers.

GridViewCollectionChangingEventArgs ?

5 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 08 Dec 2011, 05:00 PM
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;
                }
            }

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 13 Dec 2011, 03:36 PM
Hi Thomas,

Thank you for writing.

The NewItems / OldItems event arguments do not have correct values for the SortChaging event. I logged the issue and a fix for it will be available in one of our next releases. Despite my efforts I was not able to implement a work-around for the current situation.

Thank you for the report. Your Telerik points have been updated.

Best wishes,
Julian Benkov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Jason Parrish
Top achievements
Rank 1
answered on 14 Dec 2011, 04:07 PM
This also appears to occur for Filtering as well.
0
Julian Benkov
Telerik team
answered on 19 Dec 2011, 10:00 AM
Hi guys,

I am glad to inform you that the issue is planned to be addressed in our upcoming Service Pack scheduled for this week.

Best wishes,

Julian Benkov
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Johannes
Top achievements
Rank 1
answered on 25 Jan 2013, 04:15 PM
This issue still exists (I am using Q3 2012 SP1). The EventArgs members "OldItems" and "NewItems" sometimes do not have correct values.

What I wanted to achieve is to get a BindingSource updated when an user changes the sorting of a RadGridView on the same Form. Call it kind of "sorting synchronisation" (Direction and Property/ColumnName) between the two of them. This is what I use until the error is fixed... if so.

private void DataGrid_SortChanged(object sender, GridViewCollectionChangedEventArgs e)
{
    // ...

    SortDescriptor sortDescriptor;
 
    if (e.OldItems != null && e.OldItems[0] as SortDescriptor != null)
    {
        sortDescriptor = (SortDescriptor) e.OldItems[0];
        Debug.WriteLine("Using OldItem for Sorting: " + sortDescriptor.PropertyName + " " + sortDescriptor.Direction);
    }
    else
    {
        if (e.NewItems != null && e.NewItems[0] as SortDescriptor != null)
        {
            sortDescriptor = (SortDescriptor) e.NewItems[0];
            Debug.WriteLine("Using NewItem for Sorting: " + sortDescriptor.PropertyName + " " + sortDescriptor.Direction);
        }
    }

    if (sortDescriptor == null) return;

    var direction = (sortDescriptor.Direction == ListSortDirection.Ascending)
                    ? "ASC"
                    : "DESC";

    MyBindingSource.Sort = String.Concat(sortDescriptor.PropertyName, " ", direction);
}
0
Julian Benkov
Telerik team
answered on 30 Jan 2013, 02:38 PM
Hello Johannes,

I have tested the RadGridView sorting operation and the SortChanging event handler and I did not find any issues with the OldItems and NewItems collection content. If you continue to experience the same issue, please send us a simple project with some part of your data to investigate the issue locally.

Thank you for your time and cooperation. 

Kind regards,
Julian Benkov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Jason Parrish
Top achievements
Rank 1
Johannes
Top achievements
Rank 1
Share this question
or