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

Change selected row background color

3 Answers 1168 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Leo
Top achievements
Rank 1
Leo asked on 10 Apr 2013, 08:53 PM
I created the following style:

<Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource {x:Type telerik:GridViewRow}}">
             
            <Setter Property="Background" Value="LightGray" />
 
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="CornflowerBlue" />
                    <Setter Property="Foreground" Value="White"/>
                </Trigger>
 
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="LightBlue" />
                </Trigger>
            </Style.Triggers>
        </Style>

Everything works perfectly except this line:
<Setter Property="Background" Value="CornflowerBlue" />

So, how can I set the background color of a selected row?

3 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 11 Apr 2013, 08:11 AM
Hello Leo,

If you want to modify the appearance of the selected row, you can predefine its template using Microsoft Expression Blend. There you should modify the Border element named Background_Selected in the way you need. I can suggest you to check this help article for a reference.

I hope this information helps.

Greetings,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Alexander
Top achievements
Rank 1
answered on 18 Nov 2015, 04:56 PM

Hello.

In my scenario, I don't want to change the default style or a default color of the selected row. But in certain conditions, I would like to change the selection color of the specific row.

For example from the SelectionChanged event handler of RadGridView, if a certain condition occurs, I would like to highlight the selected row (or rows) in a different color.

The problem is that there is no such property like:

myGrid.SelectedItem.Background = Brushes.Red  (and I want this to happen only for this specific time, and not always)

 

I hope you can help me,

Thanks in advance

0
Yoan
Telerik team
answered on 23 Nov 2015, 11:49 AM
Hello Alexander,

You can achieve your goal, by using a RowStyleSelector. Please check this help article for a reference. In your case, you can add a property of the business object (for example "IsActive") which will control when the row will switch its color. Then in the selection changed event, after some custom logic, you can set the IsActive property to True and the row should change its color.

Regards,
Yoan
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
Leo
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or