Collapse a group of a selcted row in SfDataGrid

Hi,

In my program in winforms c# I have a sfDataGrid populated with a observable collection and I've enabled the grouping function.

How can I collapse the group of a selected row when I press the left arrow key and expande the group when I press right arrow key?

I attach a screenshot below to better understand my request:

Image_6701_1770827100295


Another question, in "Gar." how can I display "NO" instead of "False"?


Image_7922_1770827462963


and also show the Italian text in the filters.


Thanks in advance,

best regards


3 Replies

SR Senthilkumar Ranganathan Syncfusion Team February 12, 2026 01:34 PM UTC

Hi Maurizio,

Query 1: Regarding expand/collapse using left and right arrow keys
We have reviewed your query. Based on the details you provided, we checked the scenario on our side. However, we were unable to replicate the reported scenario. In DataGrid, by default, the selected group collapses when pressing the Left Arrow key and expands when pressing the Right Arrow key, and it is working as expected
To help us reproduce the problem and provide an appropriate solution, please share the following details:
  • Could you please provide details on how you are trying to perform the expand/collapse action using keyboard keys?
  • Could you please confirm whether you are facing the reported scenario in our provided sample?
  • Additionally, please share any modifications applied to your sample compared to the provided sample.
  • Kindly modify the provided sample to demonstrate the reported scenario.
This information will allow us to replicate the issue accurately and assist you further.

Query 2: Regarding changing the “Select All” text in the GridFilterControl 
In GridFilterControl, the SfListView is used internally for the CheckBoxFilterControl. To localize the “Select All” text in the CheckBoxFilterControl, you need to include the resource file of SfListView in your project and add a value for the resource key “SelectAll” based on your localization.
UG Link: Localization

Query 3: Regarding customizing the Boolean values
In a DataGrid, the underlying binding collection values cannot be localized automatically, It will be loaded based on the underling values. Therefore, you need to manually modify the displayed text according to your culture.
To customize the GroupCaptionText, you can use the SfDataGrid.DrawCell event. Within this event, you can update the display text for the GroupCaptionRow. We already have a Knowledge Base (KB) article that explains how to customize the group caption text.
To customize the True/False text in the GridFilterControl, you can modify the display text of the boolean filter items using the sfDataGrid.FilterPopupShown event. In this event, you can modify the DisplayText of the FilterElement based on your culture.
Code snippet for customizing the Boolean values:

sfDataGrid.FilterPopupShown += SfDataGrid_FilterPopupShown;

private void SfDataGrid_FilterPopupShown(object sender, Syncfusion.WinForms.DataGrid.Events.FilterPopupShownEventArgs e)
{
    if (e.Column.MappingName == "IsSelected" && e.UniqueItems != null)
    {
        foreach (var item in e.UniqueItems)
        {
            if (item.ActualValue is bool b)
                item.DisplayText = b ? "Sì" : "No";
        }
    }
}

Gif Illustration:


Please find the sample demo in the attachment.

Regards,
Senthilkumar Ranganathan.

Attachment: SfDataGridDemo_62b44fbe.zip


MA Maurizio February 13, 2026 09:19 AM UTC

Hi, 

thanks for your reply, your attachment works as expected regarding the Italian translation and I have solved requests 2 and 3.

Regarding the grouping issue, when I am in the group caption and I press the right and left arrows it works correctly like in your example, my request is to collapse or expand the group when I am in a row of a record in the group and not in a group caption row, like in the screenshot:

Image_1398_1770974149555

I've selcted navigationmode = row and  I need to intercept the group the row belongs to and expand or collapse the group or subgroup.

Image_7402_1770974283784


Thanks

best regards



SR Senthilkumar Ranganathan Syncfusion Team February 16, 2026 01:32 PM UTC

Maurizio,

We have reviewed your query and understand your requirement to expand or collapse grouped rows using the left and right arrow keys while the focus is on a record row. 
 
This functionality can be implemented using the SfDataGrid.ExpandGroup and SfDataGrid.CollapseGroup methods. In the DataGrid.TableControl.KeyDown event, the SfDataGrid.SelectedItem is used to identify the group associated with the selected record. That group is then passed to the appropriate method, allowing the group to expand when the Right Arrow key is pressed and collapse when the Left Arrow key is pressed.


Code Snippet for Expand/Collapse group row while pressing Right/Left key:

sfDataGrid.TableControl.KeyDown += SfDataGrid_KeyDown;

private void SfDataGrid_KeyDown(object sender, KeyEventArgs e)
{
    var selectedItem = sfDataGrid.SelectedItem;
    var keycode = e.KeyCode;

    if (sfDataGrid.View == null || selectedItem == null ||
        (keycode != Keys.Left && keycode != Keys.Right))
        return;

    var record = sfDataGrid.View.Records
        .FirstOrDefault(r => ReferenceEquals(r.Data, selectedItem)

    var group = record?.Parent as Group;
    if (group == null) return;

    if (keycode == Keys.Left)
    {
        for (var g = group; g != null; g = g.Parent as Group)
        {
            if (g.IsExpanded && g.Key != null && g.Parent != null)
            {
                sfDataGrid.CollapseGroup(g);
                list.Add(g);
                return;
            }
        }
    }
    else if (keycode == Keys.Right)
    {
        for (var g = list.Count - 1; g >= 0; g--)
        {
            if (!list[g].IsExpanded)
            {
                sfDataGrid.ExpandGroup(list[g]);
                return;
            }
        }
    }
}

Gif Illustration:

Note: We have provided the customization by iterating through the groups to expand or collapse all row groups for the selected record. If you want to expand or collapse only specific groups, you can further customize it based on your requirements. Additionally, we have provided the customization for single selection. If you need support for multiple selection, you can loop through the SelectedItems collection and apply the customization as required.

Please find the modified sample demo in the attachment.

Attachment: SfDataGridDemo_b350429f.zip

Loader.
Up arrow icon