This is a migrated thread and some comments may be shown as answers.
Radgridview current column : changing backcolor of the column's header
3 Answers 52 Views
This is a migrated thread and some comments may be shown as answers.
George C.
Top achievements
Rank 2
George C. asked on 24 Dec 2019, 03:24 PM

Greetings,

 

Supposing that a Radgridview has 4 columns and the second one is the current column (our target).

Is it possible to change backcolor of not all the rows of the current column, but only the header cell of the color  ? As if the column is highlighted or selected

I attached a picture

3 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Dec 2019, 09:16 AM

Hello, George,     

The appropriate way to customize the header cell elements is to use the ViewCellFormatting event. Please refer to the following code snippet which demonstrates how to change the color of the header cell for a particular column. 

        private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement is GridHeaderCellElement && e.Column.Name == "ProductName")
            {
                e.CellElement.DrawFill = true;
                e.CellElement.GradientStyle = GradientStyles.Solid;
                e.CellElement.BackColor = Color.Red;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            }
        }

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

Happy Holidays

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
Arash
Top achievements
Rank 1
answered on 19 Nov 2020, 10:22 AM

Hi,

I'm trying to implement this feature which works well enough except that, when the mouse moves over the column's header, the background color reverts.

Is there anyway this can be stopped so, in this case, column header stays red when the mouse moves out of the column header?

 

Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Nov 2020, 01:24 PM

Hello, Arash,

Telerik Presentation Framework provides a convenient API for applying some style settings for a specific element state, e.g. mouse hover. The following help article is quite useful on this topic: https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/override-theme-settings-at-run-time 

You can use a similar approach for the CellElement. Feel free to use the Visual Style Builder in order to get familiar with the exact element states that are available for a certain element that you want to manipulate:

The following forum post demonstrates how to use the API for changing the hot tracking color: https://www.telerik.com/forums/overrinding-theme-to-change-the-hottracking's-color 

I believe that it would your scenario. 

Regards,
Dess | Tech Support Engineer, Sr.
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/.

Asked by
George C.
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Arash
Top achievements
Rank 1
Share this question
or