Edit this page

Events

There are two events that are raised when the data in the RadGridView is sorted. The first one is the SortChanging event which is raised before the data is sorted. The second one is the SortChanged event and it is raised after the data is sorted.

void radGridView1_SortChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
}
void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
}

Private Sub RadGridView1_SortChanging(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles RadGridView1.SortChanging
End Sub
Private Sub RadGridView1_SortChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles RadGridView1.SortChanged
End Sub

From the event arguments of both events you can access the following data:

  • Action: An enumeration with values: Add, Remove, ItemChanged and Reset. The Action property notifies if a SortDescriptor is added, removed, modified or the SortDescriptors collection is cleared.

  • NewItems: Is a List of added, edited or removed SortDescriptors. For each SortDescriptor you can get its PropertyName and Direction.

You are also able to cancel the sorting operation by setting the Cancel property to True.

private void radGridView1_SortChanging1(object sender, GridViewCollectionChangingEventArgs e)
{
    e.Cancel = true;
}

Private Sub RadGridView1_SortChanging1(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles RadGridView1.SortChanging
    e.Cancel = True
End Sub

Since the SortDescriptors collection implements the INotifyPropertyChanged interface, you can use its CollectionChanged event (The arguments of this event provide the same data as the SortChanged event).

this.radGridView1.SortDescriptors.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(SortDescriptors_CollectionChanged);

AddHandler Me.RadGridView1.SortDescriptors.CollectionChanged, AddressOf SortDescriptors_CollectionChanged

void SortDescriptors_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{

}

Private Sub SortDescriptors_CollectionChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs)
End Sub

See Also