///dataGridView1是数据库回来的新数据
foreach (DataGridViewRow dgr in dataGridView1.Rows)
{
if (dgr.Cells["dt_pid"].Value != null && selectpid.Equals(dgr.Cells["dt_pid"].Value.ToString()))
{//先获取到行数
RowIndex = dgr.Index;
this.dataGridView1.Rows[RowIndex].Cells[0].Value =
Convert.ToBoolean(this.dataGridView1.Rows[RowIndex].Cells[0].Value) == true ? false : true;
this.dataGridView1.Rows[RowIndex].DefaultCellStyle.BackColor =
System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
//勾选这行
this.dataGridView1.Rows[RowIndex].Selected = true;
//同时勾选行的颜色也赋值
this.dataGridView1.Rows[RowIndex].DefaultCellStyle.SelectionBackColo=
System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192)))));
break;
}
}
C#的dataGridView刷新后已经重新排序,如何再次显示刚刚的记录而且添加上背景颜色
猜你喜欢
转载自blog.csdn.net/penghao_1/article/details/86644875
今日推荐
周排行