RadGridView Grouping

17 posts, 1 answers
  1. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    I am trying to display a set of data grouped by type. I don't want the user to set up the grouping, I just want the grid to appear with the groupings I define.

    I found this help topic:
    http://www.telerik.com/help/winforms/gridview-grouping-setting-groups-programmatically.html
    And wrote the three lines of code that it said to add:

    ' Set up grouping
    Dim descriptor As New GroupDescriptor
    descriptor.GroupNames.Add("ReportTypeId", System.ComponentModel.ListSortDirection.Ascending)
    Me.ReportGridView.GroupDescriptors.Add(descriptor)

    I run the application and I see no groupings. The grid contents look the same.

    I assume there is something else I need to do beyond what is in the help topic? Are there some grid settings I need to turn on/off to get this to work?
  2. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    I'd basically like for it to look like the screen shot I attached to this message. But currently, even with those three lines of code, the only way I can get the grouping to appear is to manually drag the column at runtime and then manually open each of the nodes.

    I would like the following:
    1) To set up the grouping in code and not allow the user to change it.
    2) No "Group by:" in the upper left corner.
    3) All groups opened by default (and preferably not closable by the user)
    4) No ":" in front of the grouping name.

    Anyone have any tips for any of these?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 13 Dec 2010 Link to this post

    Hi Deborah, hope you're well...

    have you set
    Me.RadGridView1.EnableGrouping = True

    Here is a very basic sample. Just a grid on a form
    Public Class Form1
      
        Private Sub Form1_Load(ByVal sender As System.Object,
                               ByVal e As System.EventArgs) Handles MyBase.Load
      
      
      
            Me.RadGridView1.MultiSelect = True
            Me.RadGridView1.AllowRowResize = False
            Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
      
            '// Enable Grouping
            Me.RadGridView1.EnableGrouping = True
      
            Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("A"))
            Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("B"))
            Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A1"
            rowInfo.Cells(1).Value = 2.99
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A2"
            rowInfo.Cells(1).Value = 3.99
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A3"
            rowInfo.Cells(1).Value = 3.99
            rowInfo = Me.RadGridView1.Rows.AddNew()
            rowInfo.Cells(0).Value = "A4"
            rowInfo.Cells(1).Value = 3.99
      
            Dim descriptor As New GroupDescriptor
            descriptor.GroupNames.Add("A", System.ComponentModel.ListSortDirection.Ascending)
            Me.RadGridView1.GroupDescriptors.Add(descriptor)
      
        End Sub
      
    End Class

    hope this helps, but let me know if you have further questions
    Richard
  5. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    Yes, I turned on any flag with the word "group" in it. :-)

    Interestingly, I deleted the code in the designer file that added the columns and instead "hard-coded" them in the code so it looked more like your example and now it appears to work.

    So the grouping does not work if the columns are defined within the designer?
  6. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    Intentially left blank
  7. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    I found it!

    If I set the GroupNames.Add to use the .FieldName for the column, it does not work.
    If I set the GroupNames.Add to use the .Name of the column, it does work.

    The descriptor.GroupNames.Add intellisense says that the first parameter is the "propertyName" which I understood to be the field name. But it appears to be the column name instead.
  8. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 13 Dec 2010 Link to this post

    Thanks for your help.

    My only other questions are:
    1) Is it possible to not have the "Type:" show up in the group header?
    2) Is it possible to define that we don't want the types sorted?

    Thanks again!
  9. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    Hi Deborah, 

    I'm glad that helped and that you now have it working. You can format the group row, just like formatting other rows. In this case you need to use the GroupSummaryEvaluate event. 

    E.g. For the the example that I showed above. 
    Private Sub RadGridView1_GroupSummaryEvaluate(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs) Handles RadGridView1.GroupSummaryEvaluate
        If e.SummaryItem.Name = "A" Then
            e.FormatString = [String].Format("{0}", e.Value)
        End If
    End Sub

    For more information, have a look at this link

    For your other question, the records need to be ordered by something, so you will always need to pass the sort descriptor as far as I know.

    Hope that helps. As usual, please remember to mark as answer and if you need further help, just let me know.
    All the best
    Richard 

  10. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 14 Dec 2010 Link to this post

    Thanks for your help.

    Wish there were a way to figure this stuff out without always having to post questions. The documentation does not seem to provide much (at least not that I could find.) Telerik is REALLY lucky to have people like you and Emanuel answering all of these!

    The answer to my original question in this thread I answered myself. There is no clear documentation on the parameters required for the grouping, so I assumed it was the field name, but it is the column name.

    I will mark your reply as an answer, though, because you answered my follow up question and there is no way to mark my own reply as the answer.

    Thanks again!
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    Hi Deborah,

    Pleased that I could help. I admit though, I've never tried having different field names and column names (it's just the header text I change out of the two so that was a new one for me). I didn't find anything either but glad that you have everything sorted.

    All the best
    Richard
  12. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 14 Dec 2010 Link to this post

    By convention, we name our columns with "XXXColumn".

    So if our business object property is "LastName", the field name is of course "LastName", but we name the column "LastNameColumn" so we can reference it.

    Though the Telerik column names are much less useful than other grids, such as the DataGridView because the .Name property is not the name of the control. Telerik still names the controls GridViewTextBoxColumn1.

    If Telerik is reading this ... it would be nice to update the documentation to ensure it is clear that the GroupDescriptor Add requires the .Name property of the grid column. Not the name of the column control and not the name of the field.

    Thanks again!
  13. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Dec 2010 Link to this post

    Hi Deborah,

    It's an interesting case. I've just been helping another forum user with filters and the PropertyName of the filter descriptor is also meant to indicate the column name. I tend to agree that the naming convention in this case could be clearer and would benefit from being changed to avoid confusion.

    All the best
    Richard
  14. Svett
    Admin
    Svett avatar
    728 posts

    Posted 16 Dec 2010 Link to this post

    Hello Deborah,

    Thank you for your suggestion. Our Windows Forms are WPF-like - their animations and architecture is similar to the respective features in WPF. That said, we tend to create our API following the API of the Microsoft Data Engine used in WPF.

    Kind regards,

    Svett
    the Telerik team

     

    Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
  15. Deborah
    Deborah avatar
    154 posts
    Member since:
    Sep 2010

    Posted 16 Dec 2010 Link to this post

    I was not suggesting modifying the API, but rather updating the documentation. (The API change suggestion was from Richard.)

    ESPECIALLY if you are going to use "general" WPF terms here, the DOCUMENTATION need to explain what the values are because "PropertyName" could mean lots of different things in this context.

    I actually thought it meant the property name in the business object, hence the reason I used the field name instead of the column name.

    So how difficult would it be to save a developer several hours of frustration by adding a line to the documentation explaining that the parameter is the .Name property of the column?

    Thanks for replying!
  16. Svett
    Admin
    Svett avatar
    728 posts

    Posted 21 Dec 2010 Link to this post

    Hi Deborah,

    Thank you for your feedback.

    We have always been striving to improve our documentation. Currently, we are working on new documentation articles covering the new features of our controls. In addition, we will modify the documentation article regarding the GroupDescriptors.

    If you have additional questions, feel free to write back.

    Kind regards,
    Svett
    the Telerik team
    Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
  17. William
    William avatar
    4 posts
    Member since:
    Sep 2016

    Posted 12 Oct in reply to Richard Slade Link to this post

    The parameter "EnableGrouping" is no longer available in RadGridView. What is the new parameter that does the same thing?
  18. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 14 Oct Link to this post

    Hello William,

    Thank you for writing.  

    The RadGridView.EnableGrouping property is still available and it allows grouping to occur programmatically or by user drag and drop. By default, this property is true. Additional information for grouping functionality in RadGridView is available here: http://docs.telerik.com/devtools/winforms/gridview/grouping/basic-grouping
     
    Our Demo application >> GridView >> Grouping section contains quite useful examples on this topic. It is usually located in the installation folder of the Telerik UI for WinForms suite: C:\Program Files (x86)\Telerik\UI for WinForms R3 2016\Examples\QuickStart\Bin.

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready