Hiding certain ColumnGroup Headers

7 posts, 0 answers
  1. CC
    CC avatar
    8 posts
    Member since:
    Mar 2009

    Posted 08 Sep 2015 Link to this post

    I have a column group that contains 5 rows. I wish to hide the headers of the last 4 rows. I did put in the following code in the viewcellformatting event (below, but it did not hide the column group rows. My headertext on those rows are empty, and the images are attached. "Capture2.jpg" is the image before using the viewcellformatting event code. "Before.jpg" is the event code below being implemented, and "result.png" is what I am attempting to achieve. Thanks in advance for any help.

     

        Private Sub RadGridView1_ViewCellFormatting(sender As Object, e As CellFormattingEventArgs) Handles RadGridView1.ViewCellFormatting

            If TypeOf sender Is GridHeaderCellElement Then
                e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed
                e.CellElement.AutoSize = False
                e.CellElement.MaxSize = New Size(0, 0)
               e.CellElement.MinSize = New Size(0, 0)
               e.CellElement.Size = New Size(0, 0)

           End If​

       End Sub
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 09 Sep 2015 Link to this post

    Hello,

    Thank you for writing.

    You can use the ViewRowFormatting event and set the RowElement.MaxSize property for the GridViewTableHeaderRowInfo. Thus, only the groups on the first row will be displayed. Here is a sample code snippet:
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim view As New ColumnGroupsViewDefinition()
        view.ColumnGroups.Add(New GridViewColumnGroup("Customer Contact"))
     
        view.ColumnGroups(0).Groups.Add(New GridViewColumnGroup("x"))
        view.ColumnGroups(0).Groups.Add(New GridViewColumnGroup("x"))
        view.ColumnGroups(0).Groups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(0).Groups(1).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(0).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("ContactName"))
        view.ColumnGroups(0).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns("ContactTitle"))
        view.ColumnGroups.Add(New GridViewColumnGroup("Details"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("x"))
        view.ColumnGroups(1).Groups.Add(New GridViewColumnGroup("x"))
        view.ColumnGroups(1).Groups(0).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(0).Rows(0).Columns.Add(Me.RadGridView1.Columns("Address"))
        view.ColumnGroups(1).Groups(1).Rows.Add(New GridViewColumnGroupRow())
        view.ColumnGroups(1).Groups(1).Rows(0).Columns.Add(Me.RadGridView1.Columns("Phone"))
        RadGridView1.ViewDefinition = view
        Me.RadGridView1.BestFitColumns()
    End Sub
     
    Private Sub RadGridView1_ViewRowFormatting(sender As Object, e As RowFormattingEventArgs) Handles RadGridView1.ViewRowFormatting
        If TypeOf e.RowElement.RowInfo Is GridViewTableHeaderRowInfo Then
            e.RowElement.MaxSize = New Size(e.RowElement.Size.Width, 1)
        End If
    End Sub

    Note that it is just a sample approach and it may not cover all possible cases. Feel free to modify it on a way which suits your requirement best.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. CC
    CC avatar
    8 posts
    Member since:
    Mar 2009

    Posted 09 Sep 2015 in reply to Dess Link to this post

    Perfect. That was exactly what I needed.
  5. CC
    CC avatar
    8 posts
    Member since:
    Mar 2009

    Posted 09 Sep 2015 in reply to Dess Link to this post

    Thanks, one question.....Must I create a GridViewColumnGroup (with the "X") ,

    or can I create just the GridViewColumnGroup("Customer Contact") and ​then create my GridviewColumnRow("ContactAddress"), etc?

    Added the code you provided in the ViewRowFormatting event and it removed all of the columngroup headers. but in my code, I do not have the additional GridViewColumnGroup that you have in the sample.

     

  6. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 10 Sep 2015 Link to this post

    Hello Chuck,

    Thank you for writing back.

    These are just sample GridViewColumnGroups in order to achieve the illustrated result. They are not required. You can construct the groups, rows, columns according to your specific requirement. As you need to show only the top most header cells, the ViewRowFormatting event is appropriate for limiting the header row's height.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. CC
    CC avatar
    8 posts
    Member since:
    Mar 2009

    Posted 10 Sep 2015 in reply to Dess Link to this post

    ah, I understand now. What I was thinking was that in the ViewRowFormatting event , I had to somehow check each row in the ColumnGroups, and set the ones I did not want to show to 1, but all I had to do was set the height for the entire ColumnGroup to a height, say 20, and that will display the topmost row, setting to 40 will show the top 2 columngroup rows.Thanks!

     

     

  8. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 11 Sep 2015 Link to this post

    Hello Chuck,

    Thank you for writing back.

    I am glad that you have achieved the desired look. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready