Thread: List Box
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default List Box

As an after thought, it would be necessary to have executed any use of the
value of the current ListIndex selection prior to the reset if the reset is
put into the ListBox click event.

"Vergel Adriano" wrote:

Kirk,

Either one of the code you identified should work. Where do you have it in
your code? Perhaps there are other lines that follow it which inadvertently
changes the selection. Assuming you're trying to do this when the form
loads, try putting it this way and place it as the last line of code in the
UserForm_Initialize:

If List1.ListCount 0 Then List1.ListIndex = 0

Other things to consider:
1. If you don't unload the form and just hide it, the next time you try to
show it, the Initialize event will not fire and whatever was selected before
you hid the form will be the one selected when it shows up again.
2. Step through your code to see if any lines are inadvertently changing the
listbox selection.



"kirkm" wrote:

Could someone please explain how to consistently set the first
item in the list box to selected (i.e. highlit) without needing to
click on it?

I've tried

List1.Selected(0) = True
and
list1.listindex = 0

Both *seemed* to work, but occasionaly fail.

Thanks - Kirk

PS it's not a MultiSelect listbox.