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

change color of the cell when its value was changed

2 Answers 184 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 12 Oct 2012, 11:51 PM
How to change the color of the cell when I changed its value?
rgv.CurrentRow.Cells[title].Value = newValue;
Is it possible?

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 17 Oct 2012, 06:35 AM
Hi Jei,

Thank you for writing.

You can use the CellValueChanged event of RadGridView, where you can store the cell's column name in the RowInfo.Tag and then in the CellFormatting event, you can check the tag and style the cell accordingly:
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.Row.Tag != null && e.Row.Tag.ToString().Contains(e.Column.Name))
    {
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        e.CellElement.BackColor = Color.Red;
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}
 
void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    if (e.Row.Tag == null)
    {
        e.Row.Tag = e.Column.Name;
    }
 
    if (!e.Row.Tag.ToString().Contains(e.Column.Name))
    {
        e.Row.Tag += e.Column.Name;
    }
}

I hope this helps.
 
All the best,
Stefan
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
Sam
Top achievements
Rank 1
answered on 21 Oct 2012, 02:24 PM
Great! Thanks!
Tags
GridView
Asked by
Sam
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Sam
Top achievements
Rank 1
Share this question
or