Toggle Between Enable and Disable Grouping Not Working

5 posts, 1 answers
  1. Hector
    Hector avatar
    25 posts
    Member since:
    Jul 2011

    Posted 17 Nov 2011 Link to this post

    I'm implementing grouping in a RadGridView. The grouping is working fine. I was then asked to allow the user to switch between grouping and not grouping, so I added a couple of radio buttons then I call a subroutine (VB.NET) that performs the following logic when the user clicks on either of the radio buttons:

    Private Sub Process_GroupByShipTo_CheckedChanged()
        If Not bControlsPopulated Then
            Exit Sub
        End If
        If rbGroupByShipTo.Checked Then
            rgvItems.EnableGrouping = True
            rgvItems.ShowGroupedColumns = True
        Else
            rgvItems.EnableGrouping = False
            rgvItems.ShowGroupedColumns = False
        End If
    End Sub

    Initially, when the form first loads, the default checked radio button is the Group By None radio button (rbGroupByNone). I click on the Group By Ship To radio button (rbGroupByShipTo) and grouping occurs. I click on the Group By None radio button and grouping goes away. But then, when I click on the Group By Ship To radio button once more, it no longer groups.

    I then tried repopulating the gridview with the following code, but that did not work:

    Private Sub Process_GroupByShipTo_CheckedChanged()
        If Not bControlsPopulated Then
            Exit Sub
        End If
        If rbGroupByShipTo.Checked Then
            rgvItems.EnableGrouping = True
            rgvItems.ShowGroupedColumns = True
            rgvItems.DataSource = Nothing
            rgvItems.Rows.Clear()
            PopulateDataGrid()
        Else
            rgvItems.EnableGrouping = False
            rgvItems.ShowGroupedColumns = False
        End If
    End Sub


    Thanks in advance for any suggestions,

    Hector
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 22 Nov 2011 Link to this post

    Hi Hector,

    Thank you for writing.

    I am not quite sure how did your grid get grouped by clicking the Group By Ship To radio button, since the code that you have provided did not show adding any group descriptors. However, it is possible that you do that in the method where you are populating the grid.

    I will suggest a slightly different approach, when Group By None is clicked, disable the grouping functionality. However, when groping is needed, just enable the grouping functionality and add the desired group descriptor. 

    Attached you can find a sample application. Additional information regarding grouping in RadGridView, can be found in this help article: http://www.telerik.com/help/winforms/gridview-grouping-setting-groups-programmatically.html.

    On a side note, I would like to remind you, that in order to be entitled to use our Support Services, your account should be added as a valid License Developer seat to a purchase. Please ask one of the License holders in your company to add you as a Licensed developer in order to continue using uninterrupted support services.

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Regards,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. Hector
    Hector avatar
    25 posts
    Member since:
    Jul 2011

    Posted 22 Nov 2011 Link to this post

    Thanks for your tip on adding the GroupDescriptor (which I've incorporated into a subroutine) when enabling grouping.

    However, for me, it still didn't work correctly. The grouping was being duplicated as a sub group (indented) under the main group. Ultimately, following is the code that worked (the main concept being to remove the GroupDescriptor also):

    If rbGroupByShipTo.Checked Then
        RemoveGrouping(rgvItems, "ShipToName")
        RemoveSorting(rgvItems, "ShipToName")
        rgvItems.EnableGrouping = True
        rgvItems.ShowGroupedColumns = True
        AddGrouping(rgvItems, "ShipToName")
        AddSorting(rgvItems, "ShipToName")
    Else
        RemoveGrouping(rgvItems, "ShipToName")
        RemoveSorting(rgvItems, "ShipToName")
        rgvItems.EnableGrouping = False
        rgvItems.ShowGroupedColumns = False
    End If

    P.S. I informed the powers that be about the licensing.
  4. Hector
    Hector avatar
    25 posts
    Member since:
    Jul 2011

    Posted 23 Nov 2011 Link to this post

    For your information, ultimately, following is the minimal code that worked:

    If rbGroupByShipTo.Checked Then
       RemoveGrouping(rgvItems, "ShipToName")
       RemoveSorting(rgvItems, "ShipToName")
       rgvItems.EnableGrouping = True
       rgvItems.ShowGroupedColumns = True
       AddGrouping(rgvItems, "ShipToName")
       AddSorting(rgvItems, "ShipToName")
    Else
       rgvItems.EnableGrouping = False
       rgvItems.ShowGroupedColumns = False
    End If

    That is, there was no need to remove that grouping and sorting when you disable grouping (in the Else block).
  5. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 25 Nov 2011 Link to this post

    Hi Hector,

    Thank you for writing back. 

    As you see in my example, when you need grouping you need to add the GroupDescriptor to the GroupDescriptors collection of RadGridView. When you want to remove the grouping, you should remove the desired group descriptor(s). Alternatively, you can disable the grouping by setting the EnableGrouping to false, which internally will clear the group descriptors and will hide the "Drag a column here to grouup by this column" panel. 

    I was not able to recreate the double grouping functionality. If you think that this might be caused by an issue on our end, please provide me with sample project demonstrating this behavior, so I can investigate it and log it for review if needed.

    Greetings,
    Stefan
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Back to Top