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:
Another question, in "Gar." how can I display "NO" instead of "False"?
and also show the Italian text in the filters.
Thanks in advance,
best regards
Hi Maurizio,
- 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.
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"; } } } |
Attachment: SfDataGridDemo_62b44fbe.zip
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:
I've selcted navigationmode = row and I need to intercept the group the row belongs to and expand or collapse the group or subgroup.
Thanks
best regards
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; } } } } |
Please find the modified sample demo in the attachment.
Attachment: SfDataGridDemo_b350429f.zip
- 3 Replies
- 2 Participants
-
MA Maurizio
- Feb 11, 2026 03:53 PM UTC
- Feb 16, 2026 01:32 PM UTC