View Single Post
Join Date: Jun 2006
Posts: 7
Reputation: binteron is an unknown quantity at this point 
Solved Threads: 0
binteron binteron is offline Offline
Newbie Poster

Format single Row in datagridview using a value in same row

 
0
  #1
Sep 5th, 2007
I have a simple database that displays information in various datagridview controls on the same form. One thing I would like to do is change the colour of a row if the value from a cell returns "poor", or "fair"

I call a private function to go through each row in the datagrid just after it is connected to the bingingSource. I can get it to change the colour, but it formats all the rows with that colour, and I want only the row that returned the value to be changed.

  1. private void checkForSurveyColour()
  2. {
  3. foreach (DataGridViewRow row in dataGridView1.Rows)
  4. {
  5. try
  6. {
  7. CNumColour = dataGridView1.CurrentRow.Cells["RepVisits"].FormattedValue.ToString();
  8. if (CNumColour != null)
  9. {
  10. foreach(DataGridViewCell cells in row.Cells)
  11. {
  12. if (CNumColour == "Fair")
  13. {
  14. cells.Style.ForeColor = Color.Pink;
  15. }
  16. else if (CNumColour == "Poor")
  17. {
  18. cells.Style.ForeColor = Color.Red;
  19. }
  20. }
  21. }
  22.  
  23.  
  24. }
  25. catch(System.Exception ex)
  26. {
  27.  
  28. }
  29. }
  30.  
  31.  
  32. }

Thanks.
Reply With Quote