How to retrieve the summary values when summary row is selected in WinForms GridGroupingControl?
Retrieve the summary values
You can retrieve the information of the summary row by using the SelectionChanged event of WinForms GridGroupingControl. In the given sample, when the selected row element is summary, then you can get the information of the summary row using the GridEngine.GetSummaryText method.
C#
//For summary row selection this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row | GridSelectionFlags.AlphaBlend; void TableModel_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { // Checking whether RangeType is Rows if(e.Range.RangeType == GridRangeInfoType.Rows) { for(int row = e.Range.Top; row <= e.Range.Bottom; row++) { //Retrieving each element and converting as Element object Element element = gridGroupingControl1.Table.NestedDisplayElements[row]; if(element.Kind == DisplayElementKind.Summary) { //Converting Element object as GridSummaryRow object GridSummaryRow sr = element as GridSummaryRow; if(sr != null) { foreach(GridSummaryColumnDescriptor scd in sr.SummaryRowDescriptor.SummaryColumns) { string result = GridEngine.GetSummaryText(sr.ParentGroup, scd); //print the results in the output window //Console.WriteLine("GroupLevel = {0}, SummaryColumns_Name = {1}, Value = {2}", sr.GroupLevel, scd.Name, result); MessageBox.Show("GroupLevel = " + sr.GroupLevel + ", SummaryColumns_Name = " + scd.Name + " , Value = " + result); } } } } } }
VB
'For summary row selection Me.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended Me.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Row Or GridSelectionFlags.AlphaBlend Private Sub TableModel_SelectionChanged(ByVal sender As Object, ByVal e As GridSelectionChangedEventArgs) ' Checking whether RangeType is Rows If e.Range.RangeType = GridRangeInfoType.Rows Then For row As Integer = e.Range.Top To e.Range.Bottom 'Retrieving each element and converting as Element object Dim element As Element = gridGroupingControl1.Table.NestedDisplayElements(row) If element.Kind = DisplayElementKind.Summary Then 'Converting Element object as GridSummaryRow object Dim sr As GridSummaryRow = TryCast(element, GridSummaryRow) If sr IsNot Nothing Then For Each scd As GridSummaryColumnDescriptor In sr.SummaryRowDescriptor.SummaryColumns Dim result As String = GridEngine.GetSummaryText(sr.ParentGroup, scd) 'print the results in the output window 'Console.WriteLine("GroupLevel = {0}, SummaryColumns_Name = {1}, Value = {2}", sr.GroupLevel, scd.Name, result); MessageBox.Show(result) Next scd End If End If Next row End If End Sub
After applying the properties, the Grid is displayed as follows.
Figure 1: The information of the summary row is displayed
Samples:
C#: Summary_values
VB: Summary_values
Conclusion
I hope you enjoyed learning about how to retrieve the summary values when summary row is selected in WinForms GridGroupingControl.
You can refer to our WinForms GridGrouping’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGrouping 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 GridGrouping and other WinForms components.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!