改变颜色

例子一:

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;         }     } }

上一篇:解决winform DataGridView 绑定数字值列排序不对的问题


下一篇:centos – 段错误是否意味着不良记忆