This is a migrated thread and some comments may be shown as answers.

How to change the header cell back color in radgridview?

1 Answer 776 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
tsz wai
Top achievements
Rank 1
tsz wai asked on 20 Jan 2015, 05:27 AM
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.

1 Answer, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 20 Jan 2015, 02:06 PM
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.

 
Tags
General Discussions
Asked by
tsz wai
Top achievements
Rank 1
Answers by
Todor
Telerik team
Share this question
or