i have a simple question actually but i can't figure it out since i'm pretty new with all the Telerik controls.
Lets say i am displaying a 20 columns database(dynamically loaded) in a RadGridView, i would like to know how we can change the header backcolor of the 4 first columns programmatically(or with a style?). By default it is black, but is it possible to have them with a green backcolor for example and all the other stay black?
Thanks in advance!
6 Answers, 1 is accepted
As you want to change the background of more than one columns' headers, it is better to create a Resource and afterwards to use it in the Property "HeaderCellStyle" of the GridViewDataColumn as a StaticResource.
The definition of the Resource is:
<UserControl.Resources> <Style x:Key="ColumnHeaderCellStyle" TargetType="telerikGridView:GridViewHeaderCell" > <Style.Setters> <Setter Property="Background" Value="Green"/> </Style.Setters> </Style></UserControl.Resources>Thus the definition of the specified column is:
<telerik:GridViewDataColumn Header ="Name" HeaderCellStyle="{StaticResource ColumnHeaderCellStyle}" DataMemberBinding="{Binding Name}" Background="Bisque">Please, make sure that you add the right assembly, containing the definition of the GridViewHeaderCell, which is:
xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"Maya
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.
We are doing a new silverlight project using RadGridView. Our requirement states that we need to load the entire literals on our forms including the header of a RadGridview from a WCF webs service. The other controls are loading just fine but the RadGridView header does not. My fear is that the header is constructed before the service returns (WCF RIA Service).
is there any way I can change this header content after it has loaded because the service is not guarantied to be available at that time
Thanks in advance
Hello Ifeanyi,
Could you please provide us with more information? What part of the header is not rendered correctly?
There should be no problem to change the Header content at runtime - you just need to get a reference to a column (using the Columns collection) and set its Header property.
All the best,
Milan
the Telerik team
We were binding the RadGridView Header to a property in our view model as below:
The Binding is on a View Model on another assembly.
How when the RadGridview loads, the column header does not show the properties in the binding. But the Grid is loaded with the CodesValues, DescriptionValues etc.
Can I use the column collection you suggested using binding and MVVM?
Thanks in advance
The way you may use the Columns Collection of the RadGridView in order to get the Headers is like:
this.RadGridView1.Columns[index].Header or this.RadGridView1.Columns[UniqueName].HeaderThus you may set the Header of each of the columns programmatically.
Another possible approach may be to expose your ViewModel as a Resource and define it as a StaticResource in the definition of the Header:
<UserControl.Resources> <my:MyViewModel x:Key="MyViewModel"/></UserControl.Resources><telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="{Binding Header1, Source={StaticResource MyViewModel}}"/>Regards,
Maya
the Telerik team
The Static Resource Option satisfied my requirement.