This is a migrated thread and some comments may be shown as answers.

Toggle Between Enable and Disable Grouping Not Working

4 Answers 298 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hector
Top achievements
Rank 1
Hector asked on 17 Nov 2011, 05:58 PM
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

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 22 Nov 2011, 11:44 AM
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.

0
Hector
Top achievements
Rank 1
answered on 22 Nov 2011, 09:52 PM
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.
0
Hector
Top achievements
Rank 1
answered on 23 Nov 2011, 02:30 PM
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).
0
Stefan
Telerik team
answered on 25 Nov 2011, 05:33 PM
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.

Tags
GridView
Asked by
Hector
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Hector
Top achievements
Rank 1
Share this question
or