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

Column BackColor

3 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 13 Jan 2011, 10:10 PM
Dear,

What is the best way to change gridview's whole column backcolor (header and all rows of a column) ?

Thanks

Marc

3 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 13 Jan 2011, 10:30 PM
Hi Marc,

For this you need to use the ViewCellFormatting event. Please consider the following code

this.radGridView1.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_ViewCellFormatting);

private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo != null)
    
        if (e.CellElement.ColumnInfo.Name == "Name")
        {
            e.CellElement.BackColor = Color.LightBlue;
            e.CellElement.NumberOfColors = 1;
            e.CellElement.DrawFill = true;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty);
            e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty);
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty);
        }           
    }
}

you can read more about formatting cells at this link

Hope that helps
Richard
0
Marc
Top achievements
Rank 1
answered on 13 Jan 2011, 10:45 PM
Thanks a lot Richard !
0
Richard Slade
Top achievements
Rank 2
answered on 13 Jan 2011, 10:50 PM
You're welcome. Please remember to mark as answer
Thanks
Richard
Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Marc
Top achievements
Rank 1
Share this question
or