GridViewCollectionChangingEventArgs ?

6 posts, 0 answers
  1. Thomas
    Thomas avatar
    34 posts
    Member since:
    Nov 2011

    Posted 08 Dec 2011 Link to this post

    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;
                    }
                }

  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Dec 2011 Link to this post

    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.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jason Parrish
    Jason Parrish avatar
    87 posts
    Member since:
    Sep 2009

    Posted 14 Dec 2011 Link to this post

    This also appears to occur for Filtering as well.
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 19 Dec 2011 Link to this post

    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.

  6. Johannes
    Johannes avatar
    66 posts
    Member since:
    Dec 2012

    Posted 25 Jan 2013 Link to this post

    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);
    }
  7. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 30 Jan 2013 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready