开发者

C# DataGridView Incorrect Scrollbar Size Causing Exception

开发者 https://www.devze.com 2023-04-10 02:02 出处:网络
I have a DataGridView and add several rows to it in a for loop (~35 rows) while it\'s Enabled property is set 开发者_如何学Cto false. I have done this in the past (when Enabled is set to true) and the

I have a DataGridView and add several rows to it in a for loop (~35 rows) while it's Enabled property is set 开发者_如何学Cto 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!


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

DataGridView.SuspendLayout()

... do the adding of the rows

DataGridView.ResumeLayout( true );


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号