If the Listbox does NOT have the focus, you can use the following code:
Dim I as Long
'This selects the first item in the list
Listbox1.Selected(0) = -1
'Use the following code only if the MultiSelected Property is set to either
"Simple Extend" or "Multi-Extended"
For I = 1 to Listbox1.ListCOunt - 1
Listbox1.Selected(I) = 0
Next I
If the Listbox does have the focus, use the following code:
Listbox1.ListIndex = 0
Notes:
The use of the ListIndex can only be used when the listbox/combobox has the
focus
When the listbox does not have the focus, the Selected Property can be
marked as true with a -1 value or marked as a 0 value.
The following is what I have learned about the listbox that seems to me at
least a bit buggy, cause it works differently than how it's documented in
the help files as the help files doesn't say anything as to when the listbox
has focus versus when it doesn't have the focus, but that's where the major
difference is at.
When the listbox does have the focus, the Selected Property DOES NOT get
updated until after the Update Event is ran on the control, so therefore,
you can't rely on the Selected Properties nor the Count Property on the
ItemsSelected Collection of the listbox. Not only that, but marking the
Selected Property with the 0 for false or -1 for true does not work that way
while the listbox has the focus. When the listbox does have the focus, the
0 on the Selected Property of an item in the list does absolutely nothing to
the state of the selection of the item while the -1 value when executed via
code as the listbox has the focus causes the state of the item's selection
to change, which means, if the item was selected, the -1 value on that
property causes the state of the selection on the item changes from true to
false, and if the item is NOT selected when the -1 value is applied to the
listbox while the listbox has the focus, the state of the selection on the
item changes from false to true.