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

[Solved] Custom Cell/Row Background/Foreground Color

1 Answer 343 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michele
Top achievements
Rank 1
Michele asked on 09 Jun 2009, 02:15 PM
Hi Telerik,

I have this code in MyGrid RowLoaded event:

if (e.Row Is GridViewRow && !(e.Row Is GridViewRow))
{
        Employee employee = e.DataElement As Employee;
        If ( employee.Name == "Michele")
        {
                ((GridViewRow)e.Row.BackGround = New SolidColorBrush(Colors.Red);
                ((GridViewRow)e.Row.Foreground = New SolidColorBrush(Colors.White);
        }    
}

The BackGround Row's property work, but Foreground property don't....... Why?

How Can I do this? And How Can I customize color's cells in the Grid's RowLoaded Event?

Thank's
Michele

1 Answer, 1 is accepted

Sort by
0
Kalin Milanov
Telerik team
answered on 10 Jun 2009, 07:25 AM
Hi Michele,

The reason you are not getting foreground color is because the cells which contain the text are part of the columns. Therefore you will need to set the foreground on the GridViewCell rather than on GridViewRow.

The easiest way of doing that is in XAML
<Style x:Key="GridViewCellStyle" TargetType="grid:GridViewCell">  
    <Setter Property="Foreground" Value="Red" /> 
</Style> 
and the assigning this style in code using DataLoaded event
void RadGridView1_DataLoaded(object sender, EventArgs e)  
{  
    foreach (var col in RadGridView1.Columns)  
    {  
        col.CellStyle = (Style)this.Resources["GridViewCellStyle"];  
    }  

This should do the trick.

Greetings,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Michele
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Share this question
or