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

[Solved] Setting background for the selected row

3 Answers 178 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yuri
Top achievements
Rank 1
Yuri asked on 05 Sep 2013, 07:03 PM
Hello,

I tried to set the background for the selected row/cell in various ways, but none seems to be working.

One was to define
<SolidColorBrush x:Key="PanelTitleBackgroundBrush" Color="#36CDF1"/>
in my StandardStyles.xaml, as described in the "Telerik Named Brushes" help topic.

Another was to have
                    <telerikGrid:RadDataGrid.Resources>
                        <Style TargetType="telerikGridPrimitives:SelectionRegionBackgroundControl">
                            <Setter Property="Background" Value="{StaticResource TelerikGridSelectedBackgroundBrush}"/>
                            <Setter Property="BorderThickness" Value="0"/>
                        </Style>
                    </telerikGrid:RadDataGrid.Resources>
added to the RadDataGrid definition, as per the "Implicit Styling" article.

What I'm trying to achieve is the simple ability to apply a background color to the selected cell/row that would differentiate it from the rest of the data in the grid.
I believe the best way to achieve this could have been just having a SelectedRowBackground property exposed by the grid itself, similarly to RowBackground and AlternateRowBackground.

Lacking that, please advise on the alternatives.

3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 06 Sep 2013, 12:17 PM
Hi Yuri,

Thank you for contacting us.

When you select an item of the RadDataGrid, the current item overrides the background of the selected item. In this case I can suggest you change the background color of the current item to Transparent through the TelerikGridCurrentCellBackgroundBrush brush. 
Then, in order to change the background color of the selected item, you can either use the TelerikGridSelectedBackgroundBrush brush or create a style that targets the SelectionRegionBackgroundControl and change its background color.
For your convenience, I have attached a project that demonstrates the two approaches.
We will also consider to improve the current logic, in order to allow turning off the DataGridCurrencyControl.

Let me know if this helps.

 

Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Yuri
Top achievements
Rank 1
answered on 06 Sep 2013, 03:15 PM
Ivaylo,

Awkward as this solution is, it could have worked... If not for the alternating rows.
Even in your sample, if I simply add 
     AlternationStep="2" AlternationStartIndex="1"
to the RadDataGrid definition, only the even-numbered rows (0, 2, etc.) will change their background color upon selection; every other row (1, 2, etc.) will keep their "alternate" color and not turn red.

Is there a workaround for that - other than giving up on the alternate rows idea altogether?
0
Ivaylo Gergov
Telerik team
answered on 06 Sep 2013, 03:48 PM
Hello Yuri,

Thank you for your valuable feedback.

I must confirm that your observations are correct. It seems that this is a bug and we will fix it for our Q3 2013 official release that will be available in mid-October. If we manage to include the fix in our Q3 2013 BETA release, that will be available by the end of the month, I will let you know in this forum thread.
Unfortunately, I cannot suggest a reasonable workaround.

If you have any other questions or suggestions do not hesitate to contact us again. I have updated your Telerik points as a token of gratitude.

 

Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Grid for XAML
Asked by
Yuri
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Yuri
Top achievements
Rank 1
Share this question
or