Windows form datagridview row color set
Hi All,
I am developing windows form using Datagridview. I have bind Datagrid from datasource.
Now, I want to set row Color for particular index in Datagridview.
I did below code but this code doing all the grid rows in one color.
foreach (DataGridViewRow dr in dgViewData.Rows)
{
if (dr.Cells["ID"].Value != null)
{
if (dr.Cells["ID"].Value.ToString() == "5" || dr.Cells["DispositionID"].Value.ToString() == "7")
{
dgViewData.DefaultCellStyle.BackColor = Color.Red;
}
else if (dr.Cells["ID"].Value.ToString() == "8")
{
dgViewAllocationData.DefaultCellStyle.BackColor = Color.Green;
}
}
}
where i am wrong ? Please help me to solve this problem.