hai expert...................
I want to chage the colour of a particular row at load time..The form is loaded on MDI parent...I have used the following code...
dataGridView1.DataSource = dt;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (Convert.ToString(dataGridView1.Rows[i].Cells[1].Value) == "OPENING BALANCE")
{
dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.AliceBlue;
dataGridView1.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
}
}
Please help me...............
Loading

Gaurish Kumar108 reputationPosted Nov 17, 2009, 12:40 AM EST
You can do this by using the rowdatabound event like this.
protected void ClientPage_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='Red'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='Gray'");
}
}
in this code I am adding the background color in event onmouseover and onmouseout
Lalit MRank #1,186 · 1.5K reputationPosted Nov 17, 2009, 2:04 AM EST
dataGridView1.Rows.Add(thresHold, "");
dataGridView1.Rows[icolor - 1].Cells[1].Style.BackColor =System.Drawing.ColorTranslator.FromOle(Convert.ToInt32(color));
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 17, 2009, 2:05 AM EST
Here is Code for performing task that you are doin
please check "do you like this answer check box " if it helps you :)
dataGridView1.DataSource = dt;
foreach (DataGridViewRow r in dataGridView1.Rows)
{
if (r.Cells[1].Value != null && r.Cells[1].Value.ToString() == "OPENING BALANCE")
{
dataGridView1.Rows[r.Index].DefaultCellStyle.BackColor = Color.AliceBlue;
dataGridView1.Rows[r.Index].DefaultCellStyle.ForeColor = Color.Red;
}
}