我在datagridview中根据数据显示不同的背景色;
 private void workBillDataGrid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
         DataGridViewRow dgr = workBillDataGrid.Rows[e.RowIndex];
            dgr.DefaultCellStyle.BackColor = Color.Orange;
            if (this.workBillDataGrid.Rows[e.RowIndex].Cells["passState"].Value.ToString() == "1")
            {
                              dgr.DefaultCellStyle.BackColor = Color.Orange;
            }
     }
但是好像感觉是死循环。放个messagebox也反复弹出来,请问如何解决??

解决方案 »

  1.   

     private void workBillDataGrid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
      {
          if (e.RowIndex >= workBillDataGrid.Rows.Count - 1)   
             return;    DataGridViewRow dgr = workBillDataGrid.Rows[e.RowIndex];
      dgr.DefaultCellStyle.BackColor = Color.Orange;
      if (this.workBillDataGrid.Rows[e.RowIndex].Cells["passState"].Value.ToString() == "1")
      {
      dgr.DefaultCellStyle.BackColor = Color.Orange;
      }
      }