Solved

Combo box mouse problems

Posted on 2002-05-31
6
135 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 88
VB6 add a minute to the date time value 8 60
VBA error replacing data 6 36
Recommendation vb6 to vb.net or others 14 104
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

948 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

20 Experts available now in Live!

Get 1:1 Help Now