Scrolling a frame at the same time as scrolling a listbox

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Scrolling a frame at the same time as scrolling a listbox

Post by Becks »

I have a Listbox showing 12 items but contains more (19 now). I have a frame which contains 19 text edit boxes, such that when a Listbox item is selected then the matched text box becomes visible ready for data entry so that the text box can be updated. The frame overlays the Listbox (Frame1.ZOrder 0)
When I scroll the listbox I want the frame to also scroll. I can do the scroll but only by capturing the MouseMove event of the Listbox, determining the TopIndex of the Listbox and then setting the ScrollTop of the Frame - very clunky because the Listbox scrollbar is not part of the region that the MouseMove event covers and the mouse has to move from the scrollbar into the Listbox before the Frame can be updated. Is there a solution? (I can live with clunky though).
Alternatively is there a scrollbar control that behaves in the same way as the list box scroll bar that I could overlay the listbox scrollbar and pass the scroll bar's movements to both the Listbox and the Frame. The scroll bar would have to show the position and the relative portion displayed which isn't how the Forms scrollbar behaves.

User avatar
HansV
Administrator
Posts: 78727
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Scrolling a frame at the same time as scrolling a listbo

Post by HansV »

Instead of a list box, I'd use the frame only, with a series of check boxes and text boxes. Ticking a check box makes the corresponding text boxes visible.
This would get rid of the problem of trying to synchronize a list box and a frame.
Best wishes,
Hans

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Re: Scrolling a frame at the same time as scrolling a listbo

Post by Becks »

Thanks Hans
That would probably solve my previous problem as well, although the Listbox appeals because it has 5 columns containing data and resizes itself to the number of rows of data in the workbook. In the past, I have built forms that have added controls at run-time so it is possible...

Becks
2StarLounger
Posts: 196
Joined: 31 Mar 2011, 03:41
Location: Perth, Western Australia

Re: Scrolling a frame at the same time as scrolling a listbo

Post by Becks »

As a follow-up, I was able to cobble together scrollbar similcrum consisting of three command buttons inside a frame that worked passibly before I "blew up" my Excel session (first time I have got a 'Catastrophic failure' message - normaly Excel crashes without such dignity :grin: ) although I hadn't resolved my previous error of disappearing highlights. I followed your suggestion and implemented a class of checkbox, labels and text edit box added inside a frame (thanks JKP for your code http://www.jkp-ads.com/Articles/ControlHandler01.asp)
Regards and :thankyou:

User avatar
HansV
Administrator
Posts: 78727
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Scrolling a frame at the same time as scrolling a listbo

Post by HansV »

Glad that uou got it working!
Best wishes,
Hans