Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a beginner programmer developing a C# WinForms solution in VS 2015 Professional for my school.

After I implemented the code below, the information on column 9 of the DataGridView is flickering and causes the fields on my form to gray out. It displays correctly only after I drag and move the form around the screen.

Can you please take a look at my code and see what the problem is? The code does what I want, but I am sure it can be perfected. Thank you. I really appreciate your time and help.

What I have tried:

C#
private void alunos_detDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
     try
     {
        decimal midtermGrade = Convert.ToInt32(this.alunos_detDataGridView.Rows[e.RowIndex].Cells[3].Value);
        decimal finalGrade = Convert.ToInt32(this.alunos_detDataGridView.Rows[e.RowIndex].Cells[4].Value);
        decimal oralGrade = Convert.ToInt32(this.alunos_detDataGridView.Rows[e.RowIndex].Cells[5].Value);

        this.alunos_detDataGridView.Rows[e.RowIndex].Cells[9].Value = ((midtermGrade + finalGrade + oralGrade) / 3);

         if (alunos_detDataGridView.CurrentRow.Cells[0].Value.ToString() != null)
         {

             if ((midtermGrade + finalGrade + oralGrade / 3) >= 60)
             {
                 this.alunos_detDataGridView.Rows[e.RowIndex].Cells[10].Value = "Aprovado";
             }
             else
             {
                this.alunos_detDataGridView.Rows[e.RowIndex].Cells[10].Value = "Reprovado";
             }
         }
     }
     catch
     {
     }
Posted

1 solution

I fixed the problem! I replaced the CellFormatting event with the CellEndEdit event and now everything is back to normal! :)
 
Share this answer
 

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