v设置符合条件某行的颜色 private void DgvNoSale_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { if (e.RowIndex >= DgvNoSale.Rows.Count) return; DataGridViewRow dgr = DgvNoSale.Rows[e.RowIndex]; int nosald = int.Parse(dgr.Cells["nosaleday"].Value.ToString()); if (nosald == 60) { dgr.DefaultCellStyle.BackColor = Color.Red; } }
//直接设置所有行的某列的颜色 DgvLowInv.Columns[0].DefaultCellStyle.ForeColor = Color.Red;
//dgvDetail.Columns["dtl_itemNumber"].DefaultCellStyle.ForeColor = Color.Red; DataGridViewCellStyle style = new DataGridViewCellStyle(dgvDetail.Rows[ia].Cells["dtl_itemNumber"].Style); style.ForeColor = Color.Red; dgvDetail.Rows[ia].Cells["dtl_itemNumber"].Style = style; //dgvDetail.Rows[ia].DefaultCellStyle.ForeColor = Color.Red; ///dgvDetail.Rows[ia].Cells["dtl_varQuantity"].
在DgvLowInv_RowPrePaint 事件中
for (int i = 0; i < DgvLowInv.Rows.Count; i++) { if (DgvLowInv.Rows[i].Cells["UNIT_CLASS"].Value.ToString() == "1") { DataGridViewCellStyle style = new DataGridViewCellStyle(DgvLowInv.Rows[i].Cells[0].Style); style.ForeColor = Color.Red; DgvLowInv.Rows[i].Cells[0].Style = style; DgvLowInv.Rows[i].Cells[1].Style = style; DgvLowInv.Rows[i].Cells[2].Style = style; DgvLowInv.Rows[i].Cells[4].Style = style; DgvLowInv.Rows[i].Cells[3].Style = style; } }