C# DataGridView 滚动条大小不正确导致异常

发布于 2024-12-08 00:14:54 字数 372 浏览 0 评论 0原文

我有一个 DataGridView 并在 for 循环中向其添加几行(约 35 行),同时它的 Enabled 属性设置为 。我过去曾这样做过(当 Enabled 设置为 true 时),与 DataGridView 的查看区域相比,垂直滚动条块将更新为适当的大小,并且网格中的项目数。然而现在,它的尺寸似乎不正确。

重新启用 DataGridView 后,我选择一行并“向下箭头”浏览各行,直到程序抛出异常,提示“值应在范围内”并引用滚动条。另外,我发现如果我对任何列进行排序,它会将滚动条块更新为正确的大小。知道发生了什么事吗?

谢谢!

I have a DataGridView and add several rows to it in a for loop (~35 rows) while it's Enabled property is set to false. I have done this in the past (when Enabled is set to true) and the vertical scroll bar block would update to the appropriate size compared to the DataGridView's viewing area and the number of items in the grid. Now, however, it appears but is the incorrect size.

After I re-enable the DataGridView, I select a row and "arrow-down" through the rows until the program throws an exception saying "Value should be within the range" and is referring to the scroll bar. Also, I discovered that if I sort any of the columns it will update the scroll bar block to the correct size. Any idea what's going on?

Thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

调妓 2024-12-15 00:14:54

我刚刚遇到了同样的问题,并按如下方式解决:

DataGridView.SuspendLayout()

...添加行

DataGridView.ResumeLayout( true );

I have just had the same issue and solved it as follows:

DataGridView.SuspendLayout()

... do the adding of the rows

DataGridView.ResumeLayout( true );

梨涡 2024-12-15 00:14:54

我最近遇到了同样的问题。

你可以这样做
1. 首先将DataSource 设置为NULL,然后再次提供Datasource。

或者

  1. 使用 BindingList 对 DataGridView 进行数据绑定。

(通过手机发布)

I recently faced same issue.

You can either do as
1. First set the DataSource to NULL then provide the Datasource again.

Or

  1. Use BindingList to DataBind the DataGridView.

(posted from mobile)

秋意浓 2024-12-15 00:14:54

我有完全相同的问题。
我尝试了一切。
最后我决定解决这个问题。当我允许AllowUserToAddRow为True时,滚动开始正常工作。

我选择在代码中处理这个新行,而不是出现错误和不正确的滚动条。也许这对某人有帮助。

I had the exact same issue.
I tried everything.
In the end I settled for a work around. When I allowed AllowUserToAddRow to True the scrolling started working correctly.

I opted to handle this new row in code rather than have the error and the incorrect scrollbar. Perhaps this helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文