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

Format Header column if grouping allowed

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ruth Goldberg
Top achievements
Rank 1
Ruth Goldberg asked on 15 Feb 2010, 08:39 PM
How can I change the format of the header text, e.g. to italics, depending on whether grouping is allowed? Is the header row processed by the CellFormatting event? From the examples I've seen, since the type of row is not checked, I assume only data rows go there. I tried the code below in the form load event, but Italic is a read-only property, so I can't change it. I'm also counting on the fact there that the columns and cells are in exactly the same order, which may not be the case.

 


Dim
i As Integer

 

 

For i = 0 To Me.TblUsersRadGridView.ColumnCount - 1

 

 

If Me.TblUsersRadGridView.Columns(i).AllowGroup Then

 

 

Me.TblUsersRadGridView.MasterGridViewInfo.TableHeaderRow.Cells(i).CellElement.Font.Italic = True

 

 

End If

 

 

Next

 

4 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 18 Feb 2010, 07:24 AM
Hi Ruth Goldberg,

Thank you for writing. Actually, you are on the right track. You can change the font through TableHeaderRow property, but you have to keep in mind that you cannot change the font style for already existed font. You have to create a new one. To make the font settings independent from the column order when referencing given cell element, you can use column names instead of index. Please, consider the following code:
Dim currentFont As Font = Me.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells("OrderID").CellElement.Font
Me.radGridView1.MasterGridViewInfo.TableHeaderRow.Cells("OrderID").CellElement.Font = New Font(currentFont, FontStyle.Italic)

Do not hesitate to contact me again if you have any additional questions.

All the best,
Martin Vasilev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Ruth Goldberg
Top achievements
Rank 1
answered on 18 Feb 2010, 07:11 PM
Thanks. That works fine
0
Ruth Goldberg
Top achievements
Rank 1
answered on 01 Mar 2010, 07:17 PM
I've used this code for most of my forms with grids and it usually works. I'm calling a routine to italicize headings from my load routine (and also when the grid is refreshed, which resets the font). However, on one form it doesn't work because the cell element is always nothing. I don't know why this is happening. Is it possible that if my grid has no data (which is true in this case), the cell element will be null?
0
Martin Vasilev
Telerik team
answered on 04 Mar 2010, 07:51 AM
Hello Ruth Goldberg,

Thank you for getting back to me. If RadGridView is not bound, the header row element is not created and it is expected behavior to receive null for CellElement(s). Before applying a new font, you have to check if CellElement is not null. Let me know if you need additional assistance.

All the best,
Martin Vasilev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Ruth Goldberg
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Ruth Goldberg
Top achievements
Rank 1
Share this question
or