Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView vertical scrollbar not updating properly (Forms bug?)

I've encountered a bug (I assume) in .NET 3.5. When adding rows to a DataGridView using Rows.Add(), while the DGV is disabled, the vertical scrollbar doesn't update properly. Consequently you can't scroll all the way to the bottom of the DGV using the scrollbar or the mouse wheel after reenabling the DGV (navigating with arrow keys still works, though.)

So I'm looking for a workaround. Is there a way to force the scrollbar to update its bounds or can you manually input a new maximum value? I'd rather not have to repopulate the DGV.

*) Actually, it's the parent form that's disabled, but I assume the problem is that it propagates to the DGV control.

like image 951
ReturningTarzan Avatar asked Dec 26 '11 00:12

ReturningTarzan


3 Answers

This also solved the problem for me:

DataGridView.SuspendLayout();
DataGridView.ResumeLayout();

It can be called before the DGV is re-enabled.


UPDATE: This also does the job:

DataGridView.PerformLayout();
like image 179
Mylodon Avatar answered Oct 09 '22 05:10

Mylodon


I've just had this problem (my form was disabled while adding rows) and solved it by setting the scrollbar property of the grid to 'None' before adding the rows then setting it back to 'Both' once all my rows have been added.

like image 31
user1169275 Avatar answered Oct 09 '22 05:10

user1169275


My problem was that my vertical scrollbar disappeared completely. I flailed with all of the above suggestions and finally discovered that making the panel containing the DataGridView narrower than the form solved the problem. In my case, 16 pixels narrower worked.

like image 45
DWALK Avatar answered Oct 09 '22 05:10

DWALK