datagridview怎么让某一列变色呢

来源:百度知道 编辑:UC知道 时间:2024/05/22 04:09:09

this.dataGridView1.Columns[列下标].DefaultCellStyle.BackColor = Color.Green; //背景色
this.dataGridView1.Columns[列下标].DefaultCellStyle.ForeColor=Color.Red;//前景色

this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#CDEBFE'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}