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

Hiding certain ColumnGroup Headers

6 Answers 77 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 08 Sep 2015, 06:58 PM

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

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Sep 2015, 01:55 PM
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
0
Charles
Top achievements
Rank 1
answered on 09 Sep 2015, 03:41 PM
Perfect. That was exactly what I needed.
0
Charles
Top achievements
Rank 1
answered on 09 Sep 2015, 08:23 PM

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.

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Sep 2015, 02:05 PM
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
0
Charles
Top achievements
Rank 1
answered on 10 Sep 2015, 02:30 PM

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!

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Sep 2015, 01:00 PM
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
Tags
GridView
Asked by
Charles
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Charles
Top achievements
Rank 1
Share this question
or