private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            if (e.RowIndex >= dataGridView1.Rows.Count - 1)
                return;
            DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
            try
            {
                string[] Flag = dgr.Cells["Flag"].Value.ToString().Split('-');
                DataGridViewCellStyle cstyle = new DataGridViewCellStyle();
                cstyle.BackColor = Color.GreenYellow;

                for (int i = 0; i < Flag.Length; i++)
                {
                    if (Flag[i] == "1")
                    {

                        //dgr.DefaultCellStyle.ForeColor = Color.Blue;

                        dgr.Cells[0].Style = cstyle;
                    }
                    if (Flag[i] == "2")
                    {

                        //dgr.DefaultCellStyle.ForeColor = Color.Blue;
                        dgr.Cells[1].Style = cstyle;
                    }
                    if (Flag[i] == "3")
                    {

                        //dgr.DefaultCellStyle.ForeColor = Color.Blue;
                        dgr.Cells[2].Style = cstyle;
                    }
                    if (Flag[i] == "4")
                    {

                        //dgr.DefaultCellStyle.ForeColor = Color.Blue;

                        dgr.Cells[3].Style = cstyle;
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2021-12-02
  • 2021-12-04
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2021-08-25
  • 2021-05-02
  • 2022-12-23
  • 2021-04-03
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案