datagirdView 设定指定字母的颜色,等于H字母的为浅红色



RowPrePaint



      private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
      {
         if (e.RowIndex > 0 && dataGridView1.Rows.Count > 0)
         {

            foreach (DataGridViewRow r in dataGridView1.Rows)
            {
               foreach (DataGridViewColumn c in dataGridView1.Columns)
               {
                  if (dataGridView1.Rows[r.Index].Cells[c.Index].EditedFormattedValue.ToString().ToUpper().Trim() == "H")
                  {
                     dataGridView1.Rows[r.Index].Cells[c.Index].Style.BackColor = Color.LightCoral;
                  }
               }
            }
         }
      }


你可能感兴趣的:(C#)