深圳全飞鸿

标题: DataGridView 改变行列颜色 [打印本页]

作者: zhgc    时间: 2020-12-17 14:38
标题: DataGridView 改变行列颜色
未验证:

  1.   private void ChangBackColor()
  2.   {
  3.       if (dataGridView1.Rows.Count > 0)
  4.       {
  5.           foreach (DataGridViewRow row in dataGridView1.Rows)
  6.           {
  7.               if (row.Cells["列名"].Value.ToString() == "条件")
  8.               {
  9.                   row.Cells["列名"].Style.ForeColor = System.Drawing.Color.Red;
  10.                    row.DefaultCellStyle.ForeColor = Color.Red; //改变整行的
  11.                }
  12.            }
  13.            DataGridViewCellStyle dgvcs = new DataGridViewCellStyle();
  14.            dgvcs.BackColor = Color.Green;
  15.            dataGridView1.Columns["列名"].DefaultCellStyle = dgvcs;  //整列
  16.        }
  17.   }
复制代码





欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2