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

Alternating Column colors

1 Answer 73 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Lasse
Top achievements
Rank 1
Lasse asked on 22 Dec 2011, 10:31 AM
Hi,

Whats the best method to Alternate column colors? Which method/event to use? And how? 
PS: I use ColumnGroups and ColumnGroupViewDefinition, and its those groups i want to alternate colors between.

Regards
Svein Thomas

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 26 Dec 2011, 03:44 PM
Hello Svein,

Thank you for writing.

You can achieve the desired behavior by using the CellFormatting event of RadGridView. Here is an example:
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    e.CellElement.DrawFill = true;
    e.CellElement.NumberOfColors = 1;
    e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
 
    if (e.ColumnIndex % 2 == 0)
    {
        e.CellElement.BackColor = Color.Green;
    }
    else
    {
        e.CellElement.BackColor = Color.Yellow;
    }
}

I hope that the provided information addresses your question. Should you have any other questions, do not hesitate to contact us.
 
Regards,
Stefan
the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
Lasse
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or