Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default ListBox Questions

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default ListBox Questions

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

Still interested in help on Q2.

josh




"Josh Sale" <jsale@tril dot cod wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default ListBox Questions

Josh Sale wrote:


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.



save listbox.selected list and restore it when user try to change selection.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default ListBox Questions

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





"Kris" wrote in message
...
Josh Sale wrote:


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.



save listbox.selected list and restore it when user try to change
selection.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Answers to questions posing more questions in a workbook sbelle1 Excel Worksheet Functions 2 August 8th 09 01:02 AM
View Questions and Answer to questions I created Roibn Taylor Excel Discussion (Misc queries) 4 July 24th 08 12:05 AM
Listbox questions Shatin Excel Programming 2 February 22nd 04 05:16 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Listbox and Array questions Stuart[_5_] Excel Programming 4 September 23rd 03 11:04 PM


All times are GMT +1. The time now is 10:07 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"