#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default List Box

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default List Box

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default List Box

I am wondering if placing the reset command in the code for the click event
wouldn't be better than in the initialize event. It is the click event that
selects the last ListIndex item, so if after the selection it is reset to 0,
the first item should be in the window for the next use, whether or not the
initialize event runs. Or am I out in left field?

"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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
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.

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
Comparing List A to List B and add what's missing from List B Gilbert Excel Discussion (Misc queries) 1 July 20th 09 08:41 PM
create new list from list A, but with exclusions from a list B Harold Good Excel Worksheet Functions 3 April 11th 08 11:23 PM
validation list--list depends on the selection of first list Michael New Users to Excel 2 April 27th 06 10:23 PM
list 1 has 400 names List 2 has 4000. find manes from list 1 on 2 Ed Excel Worksheet Functions 5 September 12th 05 09:48 AM
find names on list 1 in list 2. list 1 4000 names list 2 400 name Ed Excel Worksheet Functions 1 September 4th 05 12:48 AM


All times are GMT +1. The time now is 11:14 PM.

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

About Us

"It's about Microsoft Excel"