Reputation:
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.
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
{
}
}
Upvotes: 0
Views: 200
Reputation:
I fixed the problem! I replaced the CellFormatting event with the CellEndEdit event and now everything is back to normal! Thank you all for your feedback. :)
Upvotes: 1
Reputation: 6749
I feel like the grid is continually updating and maybe it isn't stopped until you move the form; therefore removing the focus from the grid. I'm not sure without seeing the entire code or application. Try placing a break point in the code above after the form is up and flickering and see if it is being hit again and again.
Upvotes: 0