datagirdview列中的C#信息正在闪烁 [英] C# information in datagirdview column is flickering

查看:93
本文介绍了datagirdview列中的C#信息正在闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者程序员,为我的学校在VS 2015 Professional中开发C#WinForms解决方案。



我实施下面的代码后,第9栏的信息DataGridView闪烁并导致表单上的字段变灰。只有在我在屏幕上拖动并移动表格后才能正确显示。



你能看看我的代码,看看问题是什么?代码做我想要的,但我相信它可以完善。谢谢。非常感谢您的时间和帮助。



我的尝试:



  private   void  alunos_detDataGridView_CellFormatting( object  sender,DataGridViewCellFormattingEventArgs e)
{
try
{
decimal midtermGrade = Convert.ToInt32( this .alunos_detDataGridView.Rows [e.RowIndex] .Cells [ 3 ]值)。
decimal finalGrade = Convert.ToInt32( this .alunos_detDataGridView.Rows [e.RowIndex]。单元格[ 4 ]。值);
decimal oralGrade = Convert.ToInt32( this .alunos_detDataGridView.Rows [e.RowIndex]。单元格[ 5 ]。值);

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 ]。值= Aprovado;
}
else
{
this .alunos_detDataGridView .Rows [e.RowIndex] .Cells [ 10 ]。值= Reprovado;
}
}
}
catch
{
}

解决方案

我解决了这个问题!我用CellEndEdit事件替换了CellFormatting事件,现在一切都恢复正常了! :)

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:

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
     {
     }

解决方案

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


这篇关于datagirdview列中的C#信息正在闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆