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

set color of entire row with column value as parameter

3 Answers 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
NS
Top achievements
Rank 1
NS asked on 27 Jun 2008, 11:51 AM
Hi,

How can i set the background of a row to a color based on the value of one of its columns?

I have written a convert that changes the statusid to a brush but i don't know how to apply it to the row

I tried this but that didn't work
 
 
 
<Grid.Resources> 
            <Style TargetType="{x:Type Telerik:GridViewRow}">  
                <Setter Property="Background">  
                    <Setter.Value> 
                        <SolidColorBrush Color="{Binding Path=StatusId, Converter={StaticResource ConvertDocumentColor}}"></SolidColorBrush> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Grid.Resources> 

Regards,

Bram

3 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 01 Jul 2008, 11:32 AM
Hi Nicolas,
Thanks for trying our product !

I believe that the following syntax should work for your case: 

<Grid.Resources> 
            <Style TargetType="{x:Type Telerik:GridViewRow}">  
                <Setter Property="Background">  
                    <Setter.Value> 
                        <SolidColorBrush Color="{Binding Path=Data.StatusId, Converter={StaticResource ConvertDocumentColor}}"></SolidColorBrush> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
        </Grid.Resources> 

The single thing added is the  "Data."  before "StatusID".

Adding "Data" to the binding path gives you access to the actual datarow. You may alternatively use the Data[X] syntax, where X is the index of the column.
Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
NS
Top achievements
Rank 1
answered on 02 Jul 2008, 01:32 PM

Ok it handles my convert but i doesn't set the color to what is returned.

What does the background expect?

My converter

 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)  
        {  
             
            Brush returnValue;  
            string controlType = "";  
            if (value != null)  
                controlType = value.ToString();  
 
            switch (controlType)  
            {  
                case "E":  
                    returnValue = Brushes.Red;  
                    break;  
                case "D":  
                    returnValue = Brushes.Green;  
                    break;  
                default:  
                    returnValue = Brushes.White;  
                    break;  
                  
            }  
 
            return returnValue;  
        } 

Regards
0
NS
Top achievements
Rank 1
answered on 03 Jul 2008, 02:29 PM
Problem solved

I had to use system.windows.media.brush instead of system.drawing.brush

Tags
General Discussions
Asked by
NS
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
NS
Top achievements
Rank 1
Share this question
or