Solved

Combo box mouse problems

Posted on 2002-05-31
6
138 Views
Last Modified: 2010-05-02
Ive written code to make a combo box autoselect list items base on a series of key presses (e.g. 'n','a','n' would autoselect 'nancy' from a list which included 'neal',nadine,'ned'...etc.....
The algorithm detects the enter key to select the current text from the
combo box and populate a textbox with that data. (remember partial matches populate the combo box so enter is like the verifier saying 'this is the one I want'. THe problem I have is that I still want to be able to detect when the user selects something from the combobox's drop down using a mouse. Being that the mouse populates the combo box's text without any event other than "click" I am having trouble telling the difference between when the combobox is in an intermediate selection (user has only partially typed his item), and when the user has selected an item from the combo-box's drop down with the mouse.
here is the code which does this.
----------------------------------------------------------------------
Private Sub cmbProcedures_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next

strkey = KeyCode
strshift = Shift

If strkey = 40 And Shift = 4 Then
GoTo line_go
Else
If Not (strkey = 13) Then
Exit Sub
End If
End If

line_go:
strindex = cmbProcedures.ListIndex
cmbProcedures.Text = cmbProcedures.List(strindex)
End Sub
------------------------------------------------------------------------
Private Sub cmbProcedures_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print "KEYCODE:" & KeyCode

If KeyCode = 13 Then
Procs
val = "" 
Exit Sub
End If

val = Replace(val, Chr(16), "")
val = val & LCase(Chr(KeyCode))

If KeyCode = 8 Then
val = "" 
Exit Sub
End If

For I = 0 To cmbProcedures.ListCount - 1
If (InStr(1, LCase(cmbProcedures.List(I)), val) = 1) Then
cmbProcedures.Text = cmbProcedures.List(I)
Exit Sub
End If
Next I
End Sub
------------------------------------------------------------------------
Private Sub cmbProcedures_LostFocus()
val = "" 'module level variable
End Sub
------------------------------------------------------------------------
0
Comment
Question by:mccainz2
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7047833
In combobox change event?
0
 
LVL 5

Author Comment

by:mccainz2
ID: 7047865
change would fire with both the mouse and the keypress in my case...need a way to differentiate which one caused the change.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 7048281
Using a boolean flag variable could help.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:mccainz2
ID: 7055383
yup ended up setting a boolean variable on the combobox dropdown event and flipping it on the keydown event.Worked like a charm.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7056146
Glad to hear it!
Just for clarification, if "Worked like a charm", why did you punish me with "B" grade?
Cheers
0
 
LVL 5

Author Comment

by:mccainz2
ID: 7056492
Punish with a B grade???
Sheesh. AN A answer would have included more detail regarding events that could possibly (and correctly ie(not combo change)) be monitired to toggle the boolean.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question