# Events

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.

```C#
void radGridView1_GroupByChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
    
}

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

}
```

```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 *removed***GroupDescriptors**. 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*

```C#
void radGridView1_GroupByChanging1(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
    e.Cancel = true;
}
```

```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:

```C#
radGridView1.GroupDescriptors.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(GroupDescriptors_CollectionChanged);
```

```VB.NET
AddHandler Me.RadGridView1.GroupDescriptors.CollectionChanged, AddressOf GroupDescriptors_CollectionChanged
```

```C#
void GroupDescriptors_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{

}
```

```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.

> note 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

* [Basic Grouping](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/basic-grouping)

* [Custom Grouping](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/custom-grouping)

* [Formatting Group Header Row](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/formatting-group-header-row)

* [Group Aggregates](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/group-aggregates)

* [Groups Collection](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/groups-collection)

* [Setting Groups Programmatically](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/setting-groups-programmatically)

* [Sorting group rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/sorting-group-rows)

* [Using Grouping Expressions](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/using-grouping-expressions)
