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

Validating Cell Values with color changes

1 Answer 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pinaki Basu
Top achievements
Rank 1
Pinaki Basu asked on 02 Feb 2010, 02:19 PM
Hi,

I am using a datagrid in which all editable columns are shown in a different color which i am doing on cell formatting , however when data is entered in cells which is invalid i want to change the back color to Red .
 
Here i want to make sure that user is taken back to cell in which he was doing editing also when the value he has enetred is correct the back color should change back to editable back color.

Also can't we show errortext in cell directly rather then showing it on grid.

Thanks
Anuj

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 05 Feb 2010, 11:47 AM
Hello Pinaki Basu,

Thank you for writing. Actually, you can customize the appearance of a single cell based on a condion in CellFormatting event as you have already done for marking the column editable. Please, consider the following code snippet:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnIndex == 6 )
    {
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = GradientStyles.Solid;
        if ((int)e.CellElement.RowInfo.Cells[6].Value > 3) //wrong value
        {
            e.CellElement.BackColor = Color.Red;
            e.CellElement.ForeColor = Color.White;
        }
        else //editable column colors
        {
            e.CellElement.BackColor = Color.LightGray;
            e.CellElement.ResetValue(VisualElement.ForeColorProperty);
        }
    }
}

Additionally, you have one more option -- to use integrated validation capabilities in RadGridView. Please, find more info in our documentation.

Write back if you have other questions.

Greetings,
Martin Vasilev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Pinaki Basu
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or