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.
//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);
}
}
}
'Hooks the TableControlCellMouseDown event in Form_Load
AddHandler Me.gridGroupingControl1.TableControlCellMouseDown, Addressof 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
VB: GetGroupCaptionRecords-VB.zip
Conclusion
I hope you enjoyed learning how to get the records in the WinForms GridGroupingControl.
You can refer to our WinForms GridGroupingControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms GridGroupingControl and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!