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

Backcolor for current row

3 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Ian asked on 03 Jan 2019, 11:07 AM

I've spent 2 hours trying to get the colors right on a GridView......

I set the selected row color using your examples, and the RowFormatting event, but there are two colors i just can't seem to set:

- the color used when the mouse moves over a row. I've tried using the CellMouseMove (as your examples) but I them have to rest all the non-current cells back to normal, and this seems very complicated for just changing a simplecolor. Can I set this at design time? If not, how at runtime?

- same for the backcolor of the whole grid: there is a design0time BackColor on the RadRootElement, and this sometimes shows up in the designer, but not reliably. And I can't seem to set it at runtime either.

Thanks for the great support!

Ian

 

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jan 2019, 08:57 AM
Hello, Ian,  

The easiest way to achieve your requirement is to customize the theme that you are using in your application. Thus, you can customize the style for each element state separately and save the changes to your custom theme. 



You can read more details about using the Visual Style Builder here:

1.     Loading predefined themes
2.     Working with Repository Items
3.     Saving and Loading Theme Files
4.     Loading Themes from an External File
5.     Loading Themes from a Resource
6.     Applying Theme to a Control
7.     http://tv.telerik.com/watch/winforms/visualstylebuilder/whats-new-visual-style-builder-q1-2010

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
answered on 07 Jan 2019, 09:12 AM

Thanks for the reply.

Moving my UI over to using Themes seems like a lot of work, when all I want to do is change the color one one small bit of the UI. I have had a look at the whole Themes thing, and it looks complicated, and way too much for my needs (at the moment!).

Is there a non-Themes way to do this please ?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Jan 2019, 12:09 PM
Hello, Ian   

Indeed, the whole theming mechanism seems pretty complex. However, changing the selected and hot tracking color is quite easy. Please refer to the attached sample video (drag and drop over the browser to play it). 

However, if you insist on using code, you can benefit from the functionality for overriding theme values which is demonstrated in the following help article: https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/override-theme-settings-at-run-time

I have prepared the following code snippet. You can extract the names of the element states from Visual Style Builder. 

private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.Row is GridViewDataRowInfo)
    {
        e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red, "GridDataCellElement.IsCurrent");
        e.CellElement.SetThemeValueOverride(LightVisualElement.DrawFillProperty, true, "GridDataCellElement.IsCurrent");
        e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "GridDataCellElement.IsCurrent");
 
        e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red, "GridDataCellElement.HotTracking");
        e.CellElement.SetThemeValueOverride(LightVisualElement.DrawFillProperty, true, "GridDataCellElement.HotTracking");
        e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid, "GridDataCellElement.HotTracking");
    }
    else
    {
         
        e.CellElement.ResetThemeValueOverride(LightVisualElement.BackColorProperty, "GridDataCellElement.IsCurrent");
        e.CellElement.ResetThemeValueOverride(LightVisualElement.DrawFillProperty, "GridDataCellElement.IsCurrent");
        e.CellElement.ResetThemeValueOverride(LightVisualElement.GradientStyleProperty, "GridDataCellElement.IsCurrent");
 
        e.CellElement.ResetThemeValueOverride(LightVisualElement.BackColorProperty, "GridDataCellElement.HotTracking");
        e.CellElement.ResetThemeValueOverride(LightVisualElement.DrawFillProperty, "GridDataCellElement.HotTracking");
        e.CellElement.ResetThemeValueOverride(LightVisualElement.GradientStyleProperty, "GridDataCellElement.HotTracking");
    }
}

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

 Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Ian
Top achievements
Rank 2
Bronze
Iron
Iron
Share this question
or