改变颜色

例子一:

private void dataGridView1_RowPrePaint(object   sender,   DataGridViewRowPrePaintEventArgs   e) {     

{     if(e.RowIndex < dataGridView1.Rows.Count -1)     {         DataGridViewRow dgrSingle = dataGridView1.Rows[e.RowIndex];         try         {             if(dgrSingle.Cells["列名"].Value.ToString().Contains("比较值"))             {                 dgrSingle.DefaultCellStyle.ForeColor = Color.Red;             }         }         catch(Exception ex)         {             MessageBox.Show(ex.Message);         }     }

}

例子二:

private void dataGridView1_CellPainting(object sender,DataGridViewCellPaintingEventArgs e) {     if(e.RowIndex == 2 && e.ColumnIndex> =0)     {         using(SolidBrush brush = new SolidBrush(Color.Red))         {             e.Graphics.FillRectangle(brush,e.CellBounds);             e.Handled = true;         }     } }

猜你喜欢

转载自www.cnblogs.com/qiu18359243869/p/10585400.html