StyleSelector not working on RadGridView when SelectAll from code

2 Answers 187 Views
GridView Styling
Javier
Top achievements
Rank 1
Iron
Javier asked on 22 Jul 2021, 09:06 AM

Hello,

I have a custom Style Selector to modify rows backgorund when selected or mouse over in a RadGridView. The style selector  works as expected when I select an item or do a multiple selection.

The problem comes when I perform a SelectAll() in my VM (or codeBehind). In this case the StyleSelector is not apply and is aparently  using the default style for selected items. 

Curiously it does work correctly when I select all the elements with the keyboard shortcut( ctrl + A)

Here is the style selector code:

<deltaTemplate:LastFoundInUpdateStyle x:Key="LastFoundInUpdateStyle">
            <deltaTemplate:LastFoundInUpdateStyle.GridViewRowCoreStyle>
                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="Background" Value="#FFFFFFFF"/>
                    <Setter Property="SelectedBackground" Value="#FFE0E0E0"/>
                    <Setter Property="MouseOverBackground" Value="#FFF5F5F5"/>
                </Style>
            </deltaTemplate:LastFoundInUpdateStyle.GridViewRowCoreStyle>
            <deltaTemplate:LastFoundInUpdateStyle.LastFoundInUpdateGridViewRowCoreStyle>

                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="Background" Value="LightGoldenrodYellow"/>
                    <Setter Property="SelectedBackground" Value="#FFF9F964"/>
                    <Setter Property="MouseOverBackground" Value="#FFF9F964"/>
                </Style>
            </deltaTemplate:LastFoundInUpdateStyle.LastFoundInUpdateGridViewRowCoreStyle>
        </deltaTemplate:LastFoundInUpdateStyle>
And the RadGridView :
 <telerik:RadGridView              
                Grid.Row="0"
                Margin="0,0,0,10"
                x:Name="JobcardGridView"
                SelectionMode="Extended"
                ItemsSource="{Binding JobcardViewItemQueryableCollection}"
                Style="{StaticResource RadGridViewJobcardRawReviewStyle}"
                LeftFrozenColumnCount="2" 
                FilterOperatorsLoading="JobcardGridView_FilterOperatorsLoading"
                FilteringDropDownStaysOpen="False"
                HeaderRowStyle="{StaticResource GridViewHeaderRowStyle}"
                AlternateRowStyleSelector="{StaticResource LastFoundInUpdateStyleAlternate}"
                RowStyleSelector="{StaticResource LastFoundInUpdateStyle}">

Any idea where the problem might be?

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Accepted
Stenly
Telerik team
answered on 23 Jul 2021, 06:17 AM

Hello Javier,

Thank you for reaching out to us.

I have created a sample project to test the mentioned issue and indeed when using SelectAll method in code-behind the rows turn grey. This is because the focus is not on the cells and thus they mismatch the selected color.

To change this behavior, set the EnableLostFocusSelectedState property of the data grid to False. By setting it to False the selected rows won't turn grey when the data grid loses the focus. The following code snippet shows how:

<telerik:RadGridView EnableLostFocusSelectedState="False">

Also the following documentation explains about the EnableLostFocusSelectedState property:

WPF DataGrid | Stop Showing the Unfocused State | Telerik UI for WPF

I am attaching the sample project for your convenience. I hope it solves the issue you have.

If you need further assistance I will be glad to help.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Javier
Top achievements
Rank 1
Iron
answered on 23 Jul 2021, 06:36 AM

Hi Stenly,

That solve my issue. 

Thanks for quickly support.

Thanks!

Tags
GridView Styling
Asked by
Javier
Top achievements
Rank 1
Iron
Answers by
Stenly
Telerik team
Javier
Top achievements
Rank 1
Iron
Share this question
or