Change background color of row indicator cell

2 posts, 0 answers
  1. Terry
    Terry avatar
    14 posts
    Member since:
    Feb 2018

    Posted 16 Nov 2018 Link to this post

    Hi,

    For the Row indicator column on the very left. I would like to change the background color based on an entry on one of the row values. 

    I have checked out this article - https://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells

    But do not know the type in order to get the row indicator cell/column

    Thanks!

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

    Posted 16 Nov 2018 Link to this post

    Hello, Terry, 

    In order to customize the grid cells, it it suitable to use the CellFormatting/ViewCellFormatting event as you have already found out. You can find below a sample code snippet demonstrating how to color the indicator cells:

    private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        GridRowHeaderCellElement rowHeader = e.CellElement as GridRowHeaderCellElement;
        if (rowHeader != null)
        {
            e.CellElement.DrawFill = true;
            e.CellElement.BackColor = Color.Red;
            e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        }
    }

    I would recommend you to use the RadControlSpyForm tool which is quite useful for inspecting the elements. Thus, you can find very easily which elements to customize.

    I hope this information helps.

    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.
Back to Top