New to Telerik UI for WinForms? Download free 30-day trial

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

As of R1 2021 RadGridView offers two new events:

  • GroupSortChanging: Fires when the user changes the sorting of the group. The action can be canceled.
  • GroupSortChanged: Fires after the user has changed the sorting of the group.

The GridViewGroupSortChangingEventArgs gives you access to the GridViewTemplate, GroupDescriptor and the new ListSortDirection.

See Also

In this article