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
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
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
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/.