在WebForm中 在DataGridView的RowDataBound事件裡判斷並修改: if(e.Row.Cells[n].Text=="0") { e.Row.Attributes.Add("bgColor", "red"); } else if(e.Row.Cells[n].Text>"500") { e.Row.Attributes.Add("bgColor", "green"); } //這裡的n是你的列qty的下標值 在WinForm中 private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex >= dataGridView1.Rows.Count) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { if (dgr.Cells["列名"].Value.ToString() == "比较值") { dgr.DefaultCellStyle.BackColor = 设置的颜色; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } |
|
来自: goodwangLib > 《C#》