Windows Develop Bookmark and Share   
 index > Windows Forms General > suppressing automatic scrolling within FlowLayoutPanel with AutoScroll
 

suppressing automatic scrolling within FlowLayoutPanel with AutoScroll

I have a FlowLayoutPanel with AutoScroll set to true. It has a TopDown flow, alternating between a custom control which I will refer to as a “header�and then a DataGridView below each header. There can be any number of these control pairs within any given FlowLayoutPanel. As the individual DataGridViews get long, or as the number of controls within the FlowLayoutPanel get too long for the screen, a vertical scrollbar automatically appears, as would be expected.

The problem that I am having is that making a row selection within a DataGridView can cause that DataGridView to abruptly scroll to the top or bottom of the scrollable window of the FlowLayoutPanel. If the DGV isn’t entirely visible towards the top, it scrolls downwards until it is. Likewise, if the DGV isn’t entirely visible on the bottom, it scrolls upwards until it is. Although I expect this is an intended consequence of selecting a control within an auto-scrolling container, this is rather disconcerting to my users. They can see the rows they want to select quite well, and don’t care if they don’t see all the others within the same DGV. I would like to suppress this functionality, but can’t figure out how.

I was really hoping for a cancellable event for which I could write a handler and set e.Cancel to true. I can’t find such an event. Nor can I find any ScrollableControl properties which can combine to give me this effect. Any advice you can offer would be greatly appreciated.

tiltstern  Wednesday, March 22, 2006 6:16 AM

It should be noted that the inclusion of "header" controls into the FlowLayoutPanel has nothing to do with the issue. I built a very simple, reproducable case of a dialog with an AutoScroll FlowLayoutPanel containing three DataGridViews, which in total are larger than the containing dialog. Just select a row in a DGV which isn't entirely visible in the dialog, and it will scroll entirely into view.

As an aside, I'd happily attach a zip file of this case to this posting, but I can't figure out how to add an attachment. Oh well. I can email it to anyone who is curious.

In the meantime, I have resorted to coding up my own scrolling rather than using AutoScroll. But this isn't a happy state of affairs. I would much prefer to reinstate AutoScroll if I could just figure out this issue!

tiltstern  Tuesday, March 28, 2006 7:45 AM

I believe I had a similar problem. I have a FlowLayoutPanel that contains multiple DataGridViews. If I scroll down and click on a DataGridView, the FlowLayoutPanel scrolls upso the grid I want to click on is no longer in view. I ended up setting AutoSize to true and AutoScroll to falseon the FlowLayoutPanel. Then I placed the FlowLayoutPanel within a Panel, and set the Auto-Scroll on the Panel to true. Now I can scroll through grids and click on them with no problem.

Good luck!

yulia_o  Friday, April 28, 2006 3:01 PM

I've tried last posted solution but it didn't worked, perhaps something else needs to be done.

Well, I solved this "crazy jumping" behaviour by creating my own FlowLayoutPanet and using it instead of the shipped one:

public class MyFlowLayoutPanel : FlowLayoutPanel
{
protected override Point ScrollToControl(Control PobjActiveControl)
{
return AutoScrollPosition;
}
}

(Youcan apply this to"Panel class" and so to any other class that inherits from Panel)

tanitoUy  Tuesday, July 10, 2007 3:47 PM

Thank you for posting the work around. This helped me to fix one of my scrolling issue.

Sreekanth Doppalapudi  Friday, August 01, 2008 6:50 PM

You can use google to search for other answers

Custom Search

More Threads

• How do I modify column captions in DATAGRID control using vb.net?
• Trap mouse in form
• FormClosing Issue in VS2005
• navigating to next cell by using enter button in datagridview
• using the same lookup for multiple controls
• Delay when load crystal report
• Cant stop a Form from losing focus or being the active form
• WebBrowser - tracking button clicks
• new windows update offer cannot install
• How to modify a control from another class?