Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a winForm with a dataGridView control that adds and removes rows every few seconds. When the number of rows exceeds the length of the dataGridView the scroll keeps moving and resizing itself! How do I stop it from moving and resizing as rows are being added and removed?

Thanks in advance,
-DA
Posted
Comments
Jibesh 30-Jan-13 14:13pm    
one simple method will be keeping the first row as selected. whenever you insert a new row to the datagridview set the first row as selected so that you can avoid the auto scroll to the previous selected row.
d.allen101 30-Jan-13 14:17pm    
i'm not inserting i'm adding and it's more than just keeping the first row visible I want to bar to stop resizing and for the bar to move only if the user moves it
Jibesh 30-Jan-13 14:25pm    
You cannot stop the scroll bar resize and it does automatically based on the number of rows in the datagridview. there are other ways to control this but it takes lot of code - hide the scroll bar and implement the pagination like view for your grid and limit the no of rows that can display in your grid for the current height.

No matter whether you insert/add - have you tried to set the first row as selected and check the behavior it may satisfies the scrollbar jumping around issue
Sergey Alexandrovich Kryukov 30-Jan-13 14:56pm    
Why? The problem is very simple — please see my answer.
OP just don't understand how it works.
—SA
Jibesh 30-Jan-13 15:15pm    
Oh yes.. I remember that property now. thanks for brushing up my mind. :)

1 solution

You should never stop it! This is a perfectly well defined behavior. The thumb of a scroll bar gets smaller size when you add a row, to reflect its size relative to the summary height of all rows. Is it clear?

What you might really need is the ability to scroll vertically to some row you want to show. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.firstdisplayedscrollingrowindex.aspx[^].

See also:
http://stackoverflow.com/questions/8437916/how-do-i-make-the-datagridview-show-the-selected-row-winforms[^],
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/7db968a9-38be-45fc-9dbf-e283f39d9e8c/[^].

Anything else?

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900