# Groups Collection

When a group is created it is added to the *Groups* collection of the corresponding template. You can access the groups collection in the following way:

## Accessing groups

```C#
DataGroupCollection templateGroupCollection = this.radGridView1.MasterTemplate.Groups;
```

```VB.NET
Dim templateGroupCollection = Me.RadGridView1.MasterTemplate.Groups
```

You can expand and collapse groups programmatically. The code blocks below demonstrates how you can expand and collapse the first group in the *Groups* collection.

### Expanding groups

```C#
this.radGridView1.Groups[0].Expand();
```

```VB.NET
Me.RadGridView1.Groups(0).Expand()
```

### Collapse groups

```C#
this.radGridView1.Groups[0].Collapse();
```

```VB.NET
Me.RadGridView1.Groups(0).Collapse()
```

You can use **AllowGroup** property of each column to indicate whether the user will be able to group by this column or not. The default value is *true*.

### Allow groups

```C#
this.radGridView1.Columns["Country"].AllowGroup = false;
```

```VB.NET
Me.RadGridView1.Columns("Country").AllowGroup = False
```

## DataGroup class

DataGroup collections have hierarchical structure. One or more group levels could be created. Properties of the DataGroup give access to its *Level*, *Parent* and *Child* groups:

### Accessing parent/child groups

```C#
int groupLevel= this.radGridView1.Groups[0].Level;
Group<GridViewRowInfo> parentGroup = this.radGridView1.Groups[0].Parent;
DataGroupCollection groups = this.radGridView1.Groups[0].Groups;
```

```VB.NET
Dim groupLevel As Integer = Me.RadGridView1.Groups(0).Level
Dim parentGroup As Group(Of GridViewRowInfo) = Me.RadGridView1.Groups(0).Parent
Dim groups As DataGroupCollection = Me.RadGridView1.Groups(0).Groups
```

The header row of a group (*GridViewGroupRowInfo*) can be accessed using the **GroupRow** property for a particular data group, for example:

#### Accessing group header row

```C#
GridViewRowInfo groupHeaderRow = radGridView1.Groups[0].GroupRow;
```

```VB.NET
Dim groupHeaderRow = Me.RadGridView1.Groups(0).GroupRow
```

## 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)

* [Events](https://www.telerik.com/products/winforms/documentation/controls/gridview/features/grouping/events)

* [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)

* [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)
