I want to programatically set the forecolor of the radgridview row. not cell by cell.
1) please so let me know which all event i can set the forecolor.
2) Will it possible to iterate through the grid and set the forecolor for the entire row. not cell by cell
my intention is, i have two IList, i want to compare both the List and get the equivalent value and set the forecolor for the matching records.
I am using Q1, 2011 Version.
Thanks,
Shiras
8 Answers, 1 is accepted
I believe that the feature you are looking for is the Row Style Selector. It is documented here.
Let us know if this is not what you are after.
Ross
the Telerik team
You can set absolutely any property of an element with a Style. It is not just the Background property. This particular example sets the Background property, because it is just an example.
But you can set any other property in absolutely the same way, including the Foreground property. Simply replace the word Background with the word Foreground.
Please, take a look at this article before you go on.
I hope this helps.
Ross
the Telerik team
<
dgRowStyle:CustomGridViewRowStyle
x:Key
=
"rowExistingStyle"
>
<
dgRowStyle:CustomGridViewRowStyle.rowExistingStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
</
Style
>
</
dgRowStyle:CustomGridViewRowStyle.rowExistingStyle
>
<
dgRowStyle:CustomGridViewRowStyle.rowNormalStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Black"
/>
</
Style
>
</
dgRowStyle:CustomGridViewRowStyle.rowNormalStyle
>
</
dgRowStyle:CustomGridViewRowStyle
>
now for the row forecolor I am using the RowStyleSelector in the same grid. so its not going to StyleSelector class.
So I request you to please help me in merging these two requirements.
1) I dont want space between the Parent and Child grid in a Hierarchical grid.
2) based on one of the propery of my model class, the forecolor of the grid should differ.
below is the code for forecolor (from the example you gave in this support)
<
dgRowStyle:CustomGridViewRowStyle
x:Key
=
"rowExistingStyle"
>
<
dgRowStyle:CustomGridViewRowStyle.rowExistingStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
</
Style
>
</
dgRowStyle:CustomGridViewRowStyle.rowExistingStyle
>
<
dgRowStyle:CustomGridViewRowStyle.rowNormalStyle
>
<
Style
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Black"
/>
</
Style
>
</
dgRowStyle:CustomGridViewRowStyle.rowNormalStyle
>
</
dgRowStyle:CustomGridViewRowStyle
>
Both individually is working. I want both the functionality,
Thanks
You can't mix both. When you use a StyleSelector it will set the Style of the row and it will thus overwrite the RowStyle that you have defined.
Can't you move this padding setting (and anything else that you need) to all of the different styles that you will define. For example:
<
Style
x:Key
=
"RedStyle"
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
<
Setter
Property
=
"Padding"
Value
=
"0"
/>
</
Style
>
<
Style
x:Key
=
"BlackStyle"
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Black"
/>
<
Setter
Property
=
"Padding"
Value
=
"0"
/>
</
Style
>
I hope this helps. Greetings,
Ross
the Telerik team
I moved the padding as you mentioned to the StyleSelector. And I removed the the RowStyle. Now the row color works fine. but the gap between the parent and child is coming which my client will not accept.
If I am able to remove the gap between the parent and child in the StyleSelector, I am done. Please let me know your thoughts.
<
Style
x:Key
=
"GridViewRowStyle1"
TargetType
=
"telerik:GridViewRow"
>
<
Setter
Property
=
"IsTabStop"
Value
=
"False"
/>
<
Setter
Property
=
"Template"
Value
=
"{StaticResource GridViewRowTemplate}"
/>
<
Setter
Property
=
"Background"
Value
=
"{StaticResource ItemBackground}"
/>
<
Setter
Property
=
"BorderBrush"
Value
=
"{StaticResource GridView_GridLinesItemBorder}"
/>
<
Setter
Property
=
"BorderThickness"
Value
=
"0"
/>
<
Setter
Property
=
"FontWeight"
Value
=
"Normal"
/>
<
Setter
Property
=
"VerticalContentAlignment"
Value
=
"Stretch"
/>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Stretch"
/>
<
Setter
Property
=
"Padding"
Value
=
"0"
/>
</
Style
>
The above is how I have set the RowStyle. What i did is I moved all the Setter from the this to my RowStyleSelector. but still the gap is there between Parent and Child grids.
I appreciate your followup and quick response.
Thanks
Do you have alternative suggestion for the same.
Thanks,
Shiras
You cannot change the gap between child tables using simple style.
If you take a look at the default template of GridViewRow, you may see the HierarchyChildPresenter which is responsible for displaying child tables. Through editing its template just remove the default Padding of the Border element surrounding this presenter (please refer to the attached picture and to the sample project).
Then you may use this style in the corresponding StyleSelector.
Vanya Pavlova
the Telerik team