C#DataGridView未显示滚动条

发布于 2025-01-24 20:33:27 字数 1383 浏览 2 评论 0原文

我在C#中的Windows表单应用程序中进行了DataGridView。但是,当我记录的值超过9或10时。滚动条没有出现,应用程序冻结并且没有响应。我在Windows 10中测试了该应用程序正常工作,但在Windows XP中有此问题。我搜索了很多问题,但是解决方案无法解决我的问题。 我用于DataGridView的代码:

dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Visible = true));
table.Rows.Add(dataGridView1.Rows.Count + 1, thicness.Text, "FAIL");
dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));
     if (dataGridView1.Rows.Count > 1) 
     {
         if (dataGridView1.ScrollBars == ScrollBars.Both)
         {
          dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.ScrollBars = ScrollBars.Vertical));
         }
         else if (dataGridView1.ScrollBars == ScrollBars.Vertical)
         {
          dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.ScrollBars = ScrollBars.Both));
         }
         dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));
     }
     dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));

因为我在另一个函数中调用该功能。因此,我需要使用Invoke,但这似乎会影响DataGridView。然后,我尝试在新值进入时尝试更改滚动条的属性。它仅在Windows 10上起作用,而在Windows XP上不起作用。 我在驱动器中显示了应用程序冻结图片,因为由于我是新的stackoverflow,因此我不允许在问题中发布图片。

有人知道如何解决这个问题吗?

I had made a datagridview inside my windows form application in C#. However when the value I recorded exceed 9 or 10. The scrollbars is not appearing and the application freeze and not responding. I tested the application in Windows 10 is working fine but in Windows XP have this issue. I search alot same issue question but the solution couldn't solve my problem.
The code I use for datagridview:

dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Visible = true));
table.Rows.Add(dataGridView1.Rows.Count + 1, thicness.Text, "FAIL");
dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));
     if (dataGridView1.Rows.Count > 1) 
     {
         if (dataGridView1.ScrollBars == ScrollBars.Both)
         {
          dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.ScrollBars = ScrollBars.Vertical));
         }
         else if (dataGridView1.ScrollBars == ScrollBars.Vertical)
         {
          dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.ScrollBars = ScrollBars.Both));
         }
         dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));
     }
     dataGridView1.Invoke((MethodInvoker)(() => dataGridView1.Refresh()));

Because I calling the function inside another function. Therefore, I need to use Invoke but this seem effecting the datagridview. Then I try to change the properties of the scrollbars whenever new value come in. It only works on Windows 10 but not the Windows XP.
I show the application freeze picture in drive because I am not allow to post picture in the question due to I am new in stackoverflow.
https://drive.google.com/file/d/1HXCjLwDKDMhUvbOqlp0WIel-w9JrBmyy/view?usp=sharing

Anyone know how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文