)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to retrieve the summary values when summary row is selected in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 30, 2011 |
Last Revised Date: February 13, 2020

Retrieve the summary values

You can retrieve the information of the summary row by using the SelectionChanged event of 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.

Show the information of summary row

Figure 1: The information of the summary row is displayed

Samples:

C#: Summary_values

VB: Summary_values

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon