Possible Duplicate:
Show message in empty cells in GridView
By That code i am getting all the cells colored
I just need the empty one.. Can someone notice where’s my fault (Sorry I’m new to C#)
private void simpleButton1_Click(object sender, System.EventArgs e)
{
string[] msg = new string[60];
string[] error = new string[400];
for (int i = 0; i < gridView3.RowCount ; i++)
{
System.Data.DataRow Rows = gridView3.GetDataRow(i);
string cellvalue = Rows[0].ToString();
if (cellvalue == "")
{
msg[0] = "Missing 'First Name'";
error[i] = msg[0] + " - ";
gridView3.CustomDrawCell += new RowCellCustomDrawEventHandler(gridView3_CustomDrawCell);
}
}
}
private void gridView3_CustomDrawCell_1(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
{
e.Style.BackColor = Color.LightSteelBlue;
}
By the way this grid was imported from Excel
You need to register grid event only once, not in the loop.
For cell coloring use RowCellStyle event.
Customizing Appearances of Individual Rows and Cells help topic.