views:

286

answers:

2

Hi,

I have a FlowPanelControl and a custom user control (contains a label and button). I am adding instances of the custom user control to the controls collection of the panel, which flow beneath each other as expected; showing the vertical scroll bar fine too.

When a user clicks a button within one of the added user controls, it starts a timer and writes the elapsed time to the label. When multiple instances of the user control are present, there are multiple buttons with labels; all of which can be started and stopped as required. Think of them as a mini stopwatch.

My problem is that writing to the labels is changing the scroll bar location of the containing flow panel. If you scroll to the bottom and the last user control to be started was first in the list, it moves focus back up to the top.

I have tried preventing focus on the buttons but don't think this is the problem.

Does anyone know what could be causing this? Any help would be much appreciated, thanks.

A: 

I ran into the same problem when adding rows to a DataGridView. I ended up having to set the CurrentCell equal to the last cell in the Grid to get the type of functionality like that.

Not the solution you're going for, but maybe you could InsertAt(0) these controls instead of Add() so that the newest items are at the top.

hunter
@Hunter, thanks - I don't want the scroll flicking, if I start a timer at the bottom of the list and then scroll to the top, I want to scroll bar to stay at the top. Currently, it is flicking back down to the last clicked timer control. Inserting rather than adding will still leave the same problem.
Tim Peel
A: 

I solved my problem by changing the label to a text box. The scrolling no longer flickers when a value is written to one of the controls in the list.

Tim Peel