Solved

Combo box mouse problems

Posted on 2002-05-31
6
134 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now