Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

RadGridView: Changing Sort in SortChanging re-fires SortChanging

$
0
0
Hello Trey,

Thank you for writing.

I am glad that you have found a suitable solution for your specific case. However, note that when you programmatically add SortDescriptors, the SortChanging and SortChanged events are also fired. The SortChanging event is raised before the data is sorted. In the event handler the RadGridView.SortDescriptors collection is not updated yet as this is a cancelable event. If you need to clear the SortDescriptors collection, it is more suitable to use the SortChanged event when the sorting operation has already finished. Please refer to the following code snippet demonstrating how to manipulate the SortDescriptors collection avoiding an infinite loop and add programmatically a new SortDescriptor:
private void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
    if (e.NewItems != null)
    {
        this.radGridView1.SortChanged -= radGridView1_SortChanged;
 
        //add SortDescriptors according to your requirement
        Telerik.WinControls.UI.GridViewTemplate gwt = (Telerik.WinControls.UI.GridViewTemplate)sender;
        Telerik.WinControls.Data.SortDescriptor sort = (Telerik.WinControls.Data.SortDescriptor)e.NewItems[0];
 
        Telerik.WinControls.Data.SortDescriptor sort1 = new Telerik.WinControls.Data.SortDescriptor()
        {
            PropertyName = "ContactName", Direction = System.ComponentModel.ListSortDirection.Ascending
        };
 
        gwt.SortDescriptors.Clear();
        gwt.SortDescriptors.Add(sort1);
        gwt.SortDescriptors.Add(sort);
 
        this.radGridView1.SortChanged += radGridView1_SortChanged;
    }
}

Feel free to modify the code snippet on a way to achieve the desired behavior.

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>