Articles in this section

How to expand the group only when clicking on the expander cell arrow in CaptionSummaryRow in WPF DataGrid?

In WPF DataGrid (SfDataGrid) expands the CaptionSummaryRow when you click anywhere in the CaptionSummaryRow. You can expand the group only when clicking on the GridExpanderCell in CaptionSummaryRow by customization the GroupExpanding, GroupCollapsing and SelectionChanging events in DataGrid.

sfDataGrid.GroupExpanding += SfDataGrid_GroupExpanding;
sfDataGrid.GroupCollapsing += SfDataGrid_GroupCollapsing;
sfDataGrid.SelectionChanging += SfDataGrid_SelectionChanging;

private void SfDataGrid_GroupExpanding(object sender, GroupChangingEventArgs e)
{
    var visualcontainer = this.sfDataGrid.GetVisualContainer();
    var point = Mouse.GetPosition(visualcontainer);
    // Get the row and column index based on the pointer position
    var rowColumnIndex = visualcontainer.PointToCellRowColumnIndex(point);

    // When the row index is zero, the row will be header row 
    if (!rowColumnIndex.IsEmpty)
    {
        if (rowColumnIndex.ColumnIndex > 0)
        {
            e.Cancel = true;
        }
    }
}

private void SfDataGrid_GroupCollapsing(object sender, GroupChangingEventArgs e)
{
    var visualcontainer = this.sfDataGrid.GetVisualContainer();
    var point = Mouse.GetPosition(visualcontainer);
    // Get the row and column index based on the pointer position
    var rowColumnIndex = visualcontainer.PointToCellRowColumnIndex(point);

    // When the row index is zero, the row will be header row 
    if (!rowColumnIndex.IsEmpty)
    {
        if (rowColumnIndex.ColumnIndex > 0)
        {
            e.Cancel = true;
        }
    }
}

private void SfDataGrid_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
    var visualcontainer = this.sfDataGrid.GetVisualContainer();
    var point = Mouse.GetPosition(visualcontainer);
    // Get the row and column index based on the pointer position 
    var rowColumnIndex = visualcontainer.PointToCellRowColumnIndex(point);

    // When the row index is zero, the row will be header row  
    if (!rowColumnIndex.IsEmpty)
    {
        // Get the RecordEntry by passing the RowIndex 
        var rowData = this.sfDataGrid.GetRecordEntryAtRowIndex(rowColumnIndex.RowIndex);
        if (rowData == null)
            return;

        // Check if retrieved RecordEntry is group 
        if (rowData.IsGroups && rowColumnIndex.ColumnIndex > 0)
        {
            e.Cancel = true;
        }
    }
}

Shows the group expanded only when clicking on the expander cell in SfDataGrid

Take a moment to peruse the WPF DataGrid – Grouping documentation, where you can find about grouping with code examples.


Conclusion

I hope you enjoyed learning about how to expand the group only when clicking on the expander cell arrow in CaptionSummaryRow in DataGrid.
You can refer to our WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. 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