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
Kirtan PatelPosted Nov 17, 2009, 7:05 AM
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;
}
}
Lalit MPosted Nov 17, 2009, 7:04 AM
dataGridView1.Rows.Add(thresHold, "");
dataGridView1.Rows[icolor - 1].Cells[1].Style.BackColor =System.Drawing.ColorTranslator.FromOle(Convert.ToInt32(color));
Gaurish KumarPosted Nov 17, 2009, 5:40 AM
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