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

How to set background color of a single cell?

2 Answers 465 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nicole
Top achievements
Rank 1
Nicole asked on 31 May 2012, 09:10 AM
Hello team,

I want to set the background color of a single cell in my gridview.
The bound object contains a string with the hex value of the color. The property is BackcolorHex.

<telerik:RadGridView Grid.Row="11" Grid.Column="1" Grid.ColumnSpan="4"
                     AutoGenerateColumns="False"
                     ItemsSource="{Binding WorkflowView}"
                     RowHeight="25"
                     CanUserFreezeColumns="False"
                     telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True"
                     IsSynchronizedWithCurrentItem="True"
                     IsEnabled="{Binding ModelController.WorkflowHelper.IsWorkflowEditing,
                                 Converter={StaticResource InvertBoolConv}}">
    <telerik:RadGridView.Resources>
        <Style x:Key="CellBGStyle" TargetType="telerik:GridViewCell">
            <Setter Property="Background"
                    Value="{Binding Path=BackcolorHex,
                            Converter={StaticResource HexToColorConv}}">
            </Setter>
        </Style>
    </telerik:RadGridView.Resources>
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Farbe"
                                    CellStyle="{StaticResource CellBGStyle}"
                                    DataMemberBinding="{Binding Path=BackcolorHex,
                                                        Converter={StaticResource HexToColorConv}}"
                                    IsReadOnly="True"/>
 
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

This is my converter function:

public object Convert(object value, Type targetType, object parameter,
                      CultureInfo culture)
{
    Brush retVal = new SolidColorBrush(Colors.White);
 
    if (value != null && value is ModelWorkflow)
    {
        myConverter conv = new myConverter();
        retVal = conv.ToBrush(((ModelWorkflow)value).BackcolorHex);
    }
 
    return retVal;           
}

The string is shown in the cell right. But the backcolor does not change. It's always white. Could you please tell me what i'm doing wrong?

Thank you very much.

Best regards from Germany!


2 Answers, 1 is accepted

Sort by
0
Evo
Top achievements
Rank 1
answered on 26 Oct 2015, 07:54 PM

Hi Josef!

Did you managed to accomplish this? I'm having a similar problem.

0
Stefan
Telerik team
answered on 29 Oct 2015, 01:34 PM
Hi Josef, Evaristo,

For such scenario you can use the CellStyleSelector feature, supported by RadGridView.

You may also find the Cells online example useful on the matter.

Hope this helps.

Regards,
Stefan
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Nicole
Top achievements
Rank 1
Answers by
Evo
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or