set color of entire row with column value as parameter

4 posts, 1 answers
  1. NS
    NS avatar
    189 posts
    Member since:
    Jan 2007

    Posted 27 Jun 2008 Link to this post

    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
  2. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 01 Jul 2008 Link to this post

    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
  3. NS
    NS avatar
    189 posts
    Member since:
    Jan 2007

    Posted 02 Jul 2008 Link to this post

    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
  4. NS
    NS avatar
    189 posts
    Member since:
    Jan 2007

    Posted 03 Jul 2008 Link to this post

    Problem solved

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

Back to Top