Radgridview current column : changing backcolor of the column's header

4 posts, 1 answers
  1. George C.
    George C. avatar
    32 posts
    Member since:
    Sep 2018

    Posted 24 Dec 2019 Link to this post

    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

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4131 posts

    Posted 25 Dec 2019 Link to this post

    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.
  3. Arash
    Arash avatar
    8 posts
    Member since:
    Oct 2020

    Posted 19 Nov 2020 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4131 posts

    Posted 19 Nov 2020 Link to this post

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

Back to Top