RadControls for WinForms

There are two events that are raised, when the data in the RadGridView is grouped. The first one is the GroupByChanging event which is raised before the data is grouped and he second one is the GroupByChanged event raised after the data is grouped.

Copy[C#]
radGridView1.GroupByChanging += new Telerik.WinControls.UI.GridViewCollectionChangingEventHandler(radGridView1_GroupByChanging);
radGridView1.GroupByChanged += new Telerik.WinControls.UI.GridViewCollectionChangedEventHandler(radGridView1_GroupByChanged);
Copy[C#]
void radGridView1_GroupByChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{

}

void radGridView1_GroupByChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{

}
Copy[VB.NET]
Private Sub RadGridView1_GroupByChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles RadGridView1.GroupByChanged

End Sub

Private Sub RadGridView1_GroupByChanging(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles RadGridView1.GroupByChanging

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 GroupDescriptor is added, removed, modified or the GroupDescriptors collection is cleared.
  • NewItems - a List of added, edited or removedGroupDescriptors. For each GroupDescriptor you can get its GroupNames, Format, Aggregates and Expression.

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

Copy[C#]
void radGridView1_GroupByChanging1(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
    e.Cancel = true;
}
Copy[VB.NET]
Private Sub RadGridView1_GroupByChanging1(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangingEventArgs) Handles RadGridView1.GroupByChanging
    e.Cancel = True
End Sub

Since the GroupDescriptors collection implements the INotifyPropertyChanged interface, you can use its CollectionChanged event:

Copy[C#]
radGridView1.GroupDescriptors.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(GroupDescriptors_CollectionChanged);
Copy[C#]
void GroupDescriptors_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{

}
Copy[VB.NET]
AddHandler Me.RadGridView1.GroupDescriptors.CollectionChanged, AddressOf GroupDescriptors_CollectionChanged
Copy[VB.NET]
Private Sub GroupDescriptors_CollectionChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs)

End Sub

The arguments of this event provide the same data as the GroupByChanged event.