ListBox Questions

J

Josh Sale

I have an unbound ListBox on a VBA form with enough items that vertical
scrolling is required to see all of the items and have a couple of
questions:

Q1: I populate the ListBox in my VBA code and select one of the entries.
Is there a way to ensure that the selected item is scrolled into the visible
portion of the ListBox? For example if the ListBox has 50 items, can
display 20 at a time and my code has selected item 30, is there a way to
force the display of items 20 - 40?


Q2: After I populate the ListBox, I'd like to allow the user to scroll
through the ListBox but not change the selected item. I've played around
with various combinations of the Enabled and Locked properties and it seems
like if I disable or lock the control, then scrolling is disabled along with
selection.

TIA,

josh
 
J

Josh Sale

Sorry, I just figured out the answer to Q1 ... TopIndex ... duh.

Still interested in help on Q2.

josh
 
J

Josh Sale

Kris,

Thanks for the suggestion, but it doesn't seem to work!

If I create a lstBox_Change event handler, it does indeed get control when
the user clicks around in the ListBox. However, there appears to be
something that prevents selection change from working from within that event
handler. For example if I execute lstBox.Selected(4) = False from within
that event handler, the 4th item remains selected.

Based on your suggestion, I tried doing something similar using the
lstBox_AfterUpdate event. When I place my code in that event handler I am
able to alter the selected item(s) in the ListBox. This seemed like the
ticket except that under certain conditions, it appears that a whole bunch
of these events can get queued up and then my code goes into a long loop
processing those events. If I break the code while its in that loop and
look at the call stack, there is nothing obvious calling the routine (the
only entry is the frm.Show line executed way earlier).

I also tried using lstBox_BeforeUpdate. I thought that by setting the
Cancel argument to True, I could prevent the change in selection but that
didn't work either.

lstBox_Click is never raised by the types of clicking around in the ListBox
that I'm doing.

So bottom line is, I'm still stuck!

josh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top