How to change the header cell back color in radgridview?

2 posts, 0 answers
  1. tsz wai
    tsz wai avatar
    1 posts
    Member since:
    Jan 2015

    Posted 19 Jan 2015 Link to this post

    I want to set back color in the header cell, if  column is readonly, the header cell back color is green, else red.

    I found nothing method in GridViewColumn about set style.
  2. Todor Vyagov
    Admin
    Todor Vyagov avatar
    31 posts

    Posted 20 Jan 2015 Link to this post

    Hello,

    Thank you for writing.

    To format the Header cells you should use the ViewCellFormatting event:
    private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.CellElement is GridHeaderCellElement)
        {
            e.CellElement.NumberOfColors = 1;
            e.CellElement.DrawFill = true;
     
            if (e.Column.ReadOnly)
            {
                e.CellElement.BackColor = Color.Green;
            }
            else
            {
                e.CellElement.BackColor = Color.Red;
            }
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }

    More information about GridView cells formatting can be found here: Formatting Cells

    I hope this helps.

    Regards,
    Todor
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top