View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Listindex strange problem

"Amit Shanker" wrote in message
...
FYI, Office 2003 on WinXP Pro, populating a userform listbox via AddItem
method.

In the listbox, even when I can plainly see that *no* item is selected, I
get a value of 0 (zero) which indicates that the first item *is* selected
:
?fmchtlist.chtlistbox.listindex (this code in the immediate window,
executed when the userform is loaded, and the listbox is populated via
code BUT no item is yet selected)


Hi Amit,

Is this a multi-select listbox? If so, this is the expected behavior. In
a multi select listbox the ListIndex property refers to the currently
highlighted item in the list (not necessarily the same as selected, but
rather the one surrounded by the dotted line). Unless you specifically set
the ListIndex to some other value, the first item in the list will be
highlighted after loading the listbox from VBA.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm