How to get the records in the WinForms GridGroupingControl?
GroupCaptionSection
To get the records of a particular GroupCaptionSection in WinForms GridGroupingControl , you can handle the TableControlCellMouseDown event and loop through the records in that group. To run the sample, right-click any GroupCaptionCell of a group to retrieve the records that belong to that group.
C#
//Hooks the TableControlCellMouseDown event in Form_Load this.gridGroupingControl1.TableControlCellMouseDown += gridGroupingControl1_TableControlCellMouseDown; void gridGroupingControl1_TableControlCellMouseDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellMouseEventArgs e) { if(e.Inner.MouseEventArgs.Button == MouseButtons.Right) { //Gets the style for the clicked cell GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex); Element el = style.TableCellIdentity.DisplayElement; GridCaptionRow gridCaptionRow = style.TableCellIdentity.DisplayElement as GridCaptionRow; if(gridCaptionRow != null) { string s = ""; foreach (Record rec in gridCaptionRow.GetCaptionSection().ParentGroup.Records) { //Retrieves the Values from the Record s += rec.GetValue("Name").ToString() + " " + rec.GetValue("WorkingBranch").ToString() + " " + Environment.NewLine; } //Shows the Content in the MessageBox MessageBox.Show(s); } } }
VB
'Hooks the TableControlCellMouseDown event in Form_Load Me.gridGroupingControl1.TableControlCellMouseDown += gridGroupingControl1_TableControlCellMouseDown Private Sub gridGroupingControl1_TableControlCellMouseDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellMouseEventArgs) If e.Inner.MouseEventArgs.Button = MouseButtons.Right Then 'Gets the style for the clicked cell Dim style As GridTableCellStyleInfo = e.TableControl.GetTableViewStyleInfo(e.Inner.RowIndex, e.Inner.ColIndex) Dim el As Element = style.TableCellIdentity.DisplayElement Dim gridCaptionRow As GridCaptionRow = TryCast(style.TableCellIdentity.DisplayElement, GridCaptionRow) If gridCaptionRow IsNot Nothing Then Dim s As String = "" For Each rec As Record In gridCaptionRow.GetCaptionSection().ParentGroup.Records 'Retrieves the Values from the Record s &= rec.GetValue("Name").ToString() & " " & rec.GetValue("WorkingBranch").ToString() & " " & Environment.NewLine Next rec 'Shows the Content in the MessageBox MessageBox.Show(s) End If End If End Sub
The following screenshot displays the Group Caption Records.
Samples:
C#: GetGroupCaptionRecords-C#.zip
Conclusion
I hope you enjoyed learning how to get the records in the WinForms GridGroupingControl.
You can refer to WinForms GridGrouping 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 WinForms GridGrouping 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!