Articles in this section

How to keep any one specific group alone in the expanded state in .NET MAUI DataGrid?

The .NET MAUI DataGrid allows you to keep only one group expanded while the others remain collapsed.

XAML
Wire up the group expanding event in the DataGrid.

<syncfusion:SfDataGrid x:Name="dataGrid"
                    x:DataType="local:EmployeeViewModel"
                    AllowGroupExpandCollapse="True"
                    GroupExpanding="dataGrid_GroupExpanding"
                    AutoExpandGroups="False"
                    ItemsSource="{Binding Employees}">

    <syncfusion:SfDataGrid.GroupColumnDescriptions>
        <syncfusion:GroupColumnDescription ColumnName="Title" />
    </syncfusion:SfDataGrid.GroupColumnDescriptions>
</syncfusion:SfDataGrid>

C#
We retrieve the group that is about to expand from the event arguments. We then check whether there is no currently expanded group or if the group to be expanded is different from the currently expanded group. Next, we iterate through all groups in the dataGrid. For each group that is not the one currently expanding, we collapse it. After that, we set the local variable to the group that is currently expanding. Finally, we explicitly expand the group.

private Group? expandedGroup;

private void dataGrid_GroupExpanding(object sender, DataGridColumnGroupChangingEventArgs e)
{
    var group = e.Group;
    if (expandedGroup == null || group!.Key != expandedGroup.Key)
    {
        foreach (Group otherGroup in dataGrid.View!.Groups)
        {
            if (group!.Key != otherGroup.Key)
            {
                dataGrid.CollapseGroup(otherGroup);
            }
        }
        expandedGroup = group!;
        dataGrid.ExpandGroup((Group)expandedGroup!);
    }
}

Output

SfDataGrid_Grouping.gif

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to keep any one specific group alone in the expanded state in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI example to understand how to create and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied