LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default listbox, topindex, and an extra click event

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,mous eup.

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,chan ge,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...
 
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
ListBox Click Event BHatMJ Excel Discussion (Misc queries) 6 June 21st 07 09:34 PM
listbox click event help Michael Malinsky Excel Programming 4 December 23rd 05 09:27 PM
Click event on listbox IanC Excel Programming 2 April 5th 05 07:05 AM
click event on listbox CStephenson Excel Programming 1 March 22nd 05 06:21 PM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM


All times are GMT +1. The time now is 08:14 AM.

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"