Winforms RadGridView Hierarchy - change expand plus-sign backcolor?

1 Answer 96 Views
GridView
R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
R.D. Henry and Co. asked on 08 Feb 2022, 08:09 PM

Using VS2019 and 2022.1.228.40 of Telerik.  How do I change both the Hover color and Selected color of the expand button from yellow/dark yellow to colors of my choice?

I found this post that looks like what I want.  But when I try the code in the ViewCellFormatting event, I get an error that SignStyle is not a member of GridGroupExpanderCellElement.

 

Thanks for your help.

R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
commented on 08 Feb 2022, 10:22 PM

I was able to change the selection color with this code:


            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.DarkMagenta, "Selected")
            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColor2Property, Color.DarkMagenta, "Selected")
            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColor3Property, Color.DarkMagenta, "Selected")
            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColor4Property, Color.DarkMagenta, "Selected")

I tried the same code for "MouseOver" but no luck with that one.

Dinko | Tech Support Engineer
Telerik team
commented on 11 Feb 2022, 08:32 AM

Thank you for the provided details. The mentioned post is really old. May I ask you to share which theme are you using in your application so that I can correctly test it on my side? Also, can you share the full code inside the ViewCellFormatting event handler?

R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
commented on 11 Feb 2022, 05:50 PM

No theme used.

Here's the code:


        If (TypeOf e.CellElement Is GridHeaderCellElement) Then
            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.LightSteelBlue, "MouseOver")
            e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "MouseOver")
        End If

        If TypeOf e.CellElement Is GridGroupExpanderCellElement Then
            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Magenta, "MouseOver")
            e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "MouseOver")

            e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.DarkMagenta, "Selected")
            e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "Selected")
        End If

Dinko | Tech Support Engineer
Telerik team
commented on 16 Feb 2022, 01:17 PM

Thank you for the shared code snippet. I have tested your code and you are right that the mouse hovers effect is not applied. My guess was that the state name was not correct. What I have done to check it is to use our Visual Style Builder to see which state is applied when the mouse is over the button. I see that the state is called HotTracking.

Using this I was able to change the color of the button when the mouse is over it.

private void RadGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridGroupExpanderCellElement expanderCell = e.CellElement as GridGroupExpanderCellElement;
    if (expanderCell != null)
    {

        e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.DarkMagenta, "Selected");
        e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "Selected");

        e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red, "HotTracking");
        e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "HotTracking");

        e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Aqua, "HierarchyExpanderCell.IsRowSelected.IsCurrentRow.IsPinned.HotTracking");
            e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "HierarchyExpanderCell.IsRowSelected.IsCurrentRow.IsPinned.HotTracking");
    }
    else
    {
        e.CellElement.ResetThemeValueOverrides();
    }
}

The last style is applied when the button is expanded and the mouse is over the button. Here is the result on my side.

Generally speaking, I would suggest using Visual Style Builder to modify our controls and their elements. You could choose a theme and modify the controls per your needs. Then you can apply the custom theme and all controls and their parts inside your application will be customized.

 

1 Answer, 1 is accepted

Sort by
0
R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
answered on 03 Mar 2022, 06:06 PM
Thanks, Dinko, that fixed it.  Sorry for the late reply.  
Tags
GridView
Asked by
R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
R.D. Henry and Co.
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or