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

Change row color without cell formatting event

1 Answer 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dylan
Top achievements
Rank 1
Dylan asked on 05 Sep 2014, 02:40 PM
I would like to change the background color of a row when a certain task is being performed.  Once that task has completed I would like to change it back.  All the examples I have found subscribe to the RowFormatting event and then using the GridDataRowElement.Background property passed in with the RowFormattingEventArgs.  The data is already loaded into the RadGridView control so the RowFormatting event will not fire.  Even if it did, I think the code would look a lot cleaner if I could just change the color in my method without having to trigger an event.  Is there any way to get the GridDataRowElement for a row without going through the RowFormatting event?

1 Answer, 1 is accepted

Sort by
0
Dylan
Top achievements
Rank 1
answered on 09 Sep 2014, 05:26 PM
Solution from Telerik is to use the Style property within each cell:

private void radButton1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < radGridView1.Rows[0].Cells.Count; i++)
    {
        StyleCell(radGridView1.Rows[0].Cells[i]);
    }
}
private void StyleCell(GridViewCellInfo cell)
{
      
    cell.Style.CustomizeFill = true;
    cell.Style.GradientStyle = GradientStyles.Solid;
    cell.Style.BackColor = Color.FromArgb(162, 215, 255);
}
  
private void radButton2_Click(object sender, EventArgs e)
{
    for (int i = 0; i < radGridView1.Rows[0].Cells.Count; i++)
    {
        radGridView1.Rows[0].Cells[i].Style.Reset();
    }
}

Tags
GridView
Asked by
Dylan
Top achievements
Rank 1
Answers by
Dylan
Top achievements
Rank 1
Share this question
or