P
Pointrider
I have a userform with a text box and a listbox. As the user types into
the text box, I use the textbox_change event to see if the partial entry
(I use LIKE and a wildcard) has a match in the listbox, and if so I use
the listindex and topindex properties to select the match and scroll it
to the top of the listbox. No problem yet.
The listbox items are of the form "lastname, firstname", so there will
be several matches as the first characters are typed. If the user sees
the wanted match selected in the listbox, then a tab will copy the match
to the text box and move to the next form control. I use the
textbox_exit event for this, and it works fine.
Since the topindex property has scrolled the listbox so the match is on
top, the user may see the entry they want just a few items down the
list. So, typing "joh" could result in a listbox with "johnson, ann" on
top, followed by "johnson, beth". If the user wants the second entry, I
want them to be able to double-click it and then move on.
My code for the listbox_dblclick event is simple...
Private Sub NamesListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With NamesListBox
NameBox.Value = .Value
End With
End Sub
This too works fine.
Then I decided to reset the topindex with the double-click, to move the
selected item to the top of the listbox, and ran into trouble.
With the code above, the sequence of event triggers I see (for the
listbox) is:
enter,mousedown,change,click,mouseup,dblclick,mouseup.
If I reset the topindex property, the event code looks like
Private Sub NamesListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With NamesListBox
.TopIndex = .ListIndex
NameBox.Value = .Value
End With
End Sub
When I execute this, the sequence of events is
enter,mousedown,change,click,mouseup,dblclick,change,click,mouseup
There is an extra Change and an extra Click! The result is that the
correct item is scrolled to the top if the listbox, but the highlighted
(selected) item becomes the one at the mouse position when the
double-click occurred.
Does anyone know what's going on? Why the extra event triggers if I set
the topindex? Can't find anything about this anywhere on the web or in
the newsgroups.
Thanks...
the text box, I use the textbox_change event to see if the partial entry
(I use LIKE and a wildcard) has a match in the listbox, and if so I use
the listindex and topindex properties to select the match and scroll it
to the top of the listbox. No problem yet.
The listbox items are of the form "lastname, firstname", so there will
be several matches as the first characters are typed. If the user sees
the wanted match selected in the listbox, then a tab will copy the match
to the text box and move to the next form control. I use the
textbox_exit event for this, and it works fine.
Since the topindex property has scrolled the listbox so the match is on
top, the user may see the entry they want just a few items down the
list. So, typing "joh" could result in a listbox with "johnson, ann" on
top, followed by "johnson, beth". If the user wants the second entry, I
want them to be able to double-click it and then move on.
My code for the listbox_dblclick event is simple...
Private Sub NamesListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With NamesListBox
NameBox.Value = .Value
End With
End Sub
This too works fine.
Then I decided to reset the topindex with the double-click, to move the
selected item to the top of the listbox, and ran into trouble.
With the code above, the sequence of event triggers I see (for the
listbox) is:
enter,mousedown,change,click,mouseup,dblclick,mouseup.
If I reset the topindex property, the event code looks like
Private Sub NamesListBox_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With NamesListBox
.TopIndex = .ListIndex
NameBox.Value = .Value
End With
End Sub
When I execute this, the sequence of events is
enter,mousedown,change,click,mouseup,dblclick,change,click,mouseup
There is an extra Change and an extra Click! The result is that the
correct item is scrolled to the top if the listbox, but the highlighted
(selected) item becomes the one at the mouse position when the
double-click occurred.
Does anyone know what's going on? Why the extra event triggers if I set
the topindex? Can't find anything about this anywhere on the web or in
the newsgroups.
Thanks...