Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. dataGridView2_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)//I have used this event
  2.  
  3. string unit = Convert.ToString(dataGridView2.Columns["exam"]);//One of my datagridview
  4. //column name is exam and in that column cells will be unit1 or unit2 or unit3 or unit 4 or quarterly or halfyearly or yearly
  5. if (unit == "Unit 1" ||unit == "Unit1" || unit == "Unit2" || unit == "Unit3" || unit == "Unit4")
  6. {
  7. for (int i = 0; i < dataGridView2.Rows.Count; i++)
  8. {
  9.  
  10. for (int j = 7; j < dataGridView2.Rows[i].Cells.Count; j++)
  11. {
  12. if (Convert.ToInt32(dataGridView2.Rows[i].Cells[j].Value) < 13)
  13. {
  14. dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Red;
  15. }
  16.  
  17.  
  18. else
  19. {
  20. dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Green;
  21. }
  22. }
  23. }
  24.  
  25. }
  26. else
  27. {
  28. for (int i = 0; i < dataGridView2.Rows.Count; i++)
  29. {
  30.  
  31. for (int j = 7; j < dataGridView2.Rows[i].Cells.Count; j++)
  32. {
  33.  
  34. if (Convert.ToInt32(dataGridView2.Rows[i].Cells[j].Value) < 35 )
  35. dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Red;
  36. else
  37. dataGridView2.Rows[i].Cells[j].Style.ForeColor = Color.Green;
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement