您的位置:首页 > 其它

DataGridView中的行如何根据不同的值显示不同的行背景色

2007-11-14 16:41 375 查看
1.webform
在DataGridView的RowDataBound事件裡判斷並修改:
if(e.Row.Cells
.Text=="0")
{
e.Row.Attributes.Add("bgColor", "red");
}
else if(e.Row.Cells
.Text>"500")
{
e.Row.Attributes.Add("bgColor", "green");
}
//這裡的n是你的列qty的下標值
2.winform
private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
{
if (e.RowIndex >= dataGridView1.Rows.Count - 1)
return;
DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if (dgr.Cells["列名"].Value.ToString() == "比较值")
{
dgr.DefaultCellStyle.ForeColor = 设置的颜色;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐