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​
6 Answers, 1 is accepted
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.
Dess
Telerik
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.
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
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!
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