Is it possible to add an image to a Column Header instead of Text?
Many Thanks for your previous support/help.
LM
6 Answers, 1 is accepted
Yes, it is possible. Here is some sample code how to achieve this:
GridTableHeaderRowElement header = (this.radGridView1.GridElement as GridTableElement).TableBodyElement.Children[0] as GridTableHeaderRowElement; |
this.radGridView1.ImageList = this.imageList1; |
foreach(RadElement element in header.Children ) |
{ |
if (element as GridHeaderCellElement != null) |
{ |
(element as GridHeaderCellElement).ImageIndex = 0; |
} |
} |
1. I create a variable named header and initialize it with the header row element instance.
2. I set an imageList to the gridview which I will use to set images to the headers
3. I iterate through the header cell elements ( i.e column headers ) and then I set images.
4. To change the text of the columns you will have to set the Text property of the header cell elements, too.
If you have any questions please do not hesitate to write me.
Sincerely yours,
Boyko Markov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm sorry but the first line is to much for me! I using vb.net. Can you translate that code to VB.NET?
And in what event should I put that code?
Many Thanks, once more.
LM
nevermind, I found the solution and is working perfectly!
Thanks
LM
If you have any further questions, do not hesitate to write me back.
Regards,
Boyko Markov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm also using VB.net, and your normally excellent code converter can't translate line 1 - maybe you can make these kinds of code (of which there are many in lots of your examples) a little bit simpler, then the code coverter can do it's work.
Maybe a useful step when answering ALL questions - make sure the code converter works on whatever code you sugest?
Hello, Ian,
If you are trying to convert the code snippet suggested from this reply, here is the same code snippet in VB:
Dim header As GridTableHeaderRowElement = TryCast((TryCast(Me.radGridView1.GridElement, GridTableElement)).TableBodyElement.Children(0), GridTableHeaderRowElement)
Me.radGridView1.ImageList = Me.imageList1
For Each element As RadElement In header.Children
If TryCast(element, GridHeaderCellElement) IsNot Nothing Then
(TryCast(element, GridHeaderCellElement)).ImageIndex = 0
End If
Next
Note, that Telerik Converter works fine when you convert methods instead of separate code snippets.
If you have any other questions please let me know.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.