Alternating Column colors

2 posts, 0 answers
  1. Lasse
    Lasse avatar
    21 posts
    Member since:
    Jul 2011

    Posted 22 Dec 2011 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 26 Dec 2011 Link to this post

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