Click here to Skip to main content
16,021,181 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making a program in c# that takes student roll number, name, marks and grade. the first three fields are inserted by the user where as the grade is calculated automatically by the program based upon student's marks.I tried using
dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.Yellow;
But it changes the color of the next row.
this is my code for the calculate grade function:

C#
private string cal_grade()
       {
           string grade = "";
           marks = Int32.Parse(markstb.Text);
           if (marks >= 87 && marks <= 100)
           {
               dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.Yellow;
               grade = "A";
               a++;
               Albl.Text = a.ToString();

           }
           else if (marks >= 80 && marks <= 86)
           {
               grade = "B+";
               bp++;
               Bpluslbl.Text = bp.ToString();
           }
           else if (marks >= 72 && marks <= 79)
           {
               grade = "B";
               b++;
               Blbl.Text = b.ToString();
           }

           else if (marks >= 66 && marks <= 71)
           {
               grade = "C+";
               cp++;
               Cpluslbl.Text = cp.ToString();
           }

           else if (marks >= 61 && marks <= 65)
           {
               grade = "C";
               c++;
               Clbl.Text = c.ToString();
           }
           else if (marks >= 50 && marks <= 60)
           {
               grade = "D";
               d++;
               Dlbl.Text = d.ToString();
           }
           else if (marks <= 50)
           {
               grade = "F";
               f++;
               Flbl.Text = f.ToString();
           }
           return grade;
       }
Posted
Updated 14-Mar-14 9:09am
v2
Comments
Sergey Alexandrovich Kryukov 14-Mar-14 15:10pm    
I added the tag "System.Windows.Forms" to your question; is that correct? Next time, always make sure you inform of the UI framework/library you are using in your tags.
—SA
Member 10377493 14-Mar-14 15:46pm    
yes thats right thnk you very much.Can you please guide me on this issue?
Sergey Alexandrovich Kryukov 14-Mar-14 15:54pm    
How about my answer? Generally, such problems are easily solved, I happened to set row style just recently, achieved by setting cell style in a cycle for some of the rows; this is the way to get different styles for different rows of the save grid view. You only need to pay more attention...
—SA
Member 10377493 14-Mar-14 15:21pm    
can any body please answer this question of mine?

1 solution

 
Share this answer
 
Comments
Member 10377493 14-Mar-14 17:08pm    
thanks alot that worked for me :)
Sergey Alexandrovich Kryukov 14-Mar-14 17:23pm    
Great. You are very welcome.
Good luck, call again.
—SA
Maciej Los 14-Mar-14 17:09pm    
Short and to the point!
+5!
Sergey Alexandrovich Kryukov 14-Mar-14 17:23pm    
Thank you, Maciej.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900