Solved

Detect when Combo Box Retracts

Posted on 2001-06-12
8
228 Views
Last Modified: 2010-05-02
I want to detect when a combobox drop down retracts.  The goal is to move focus to another control when the user selects an item.

Any other solution is equally acceptable

I have the following in the click event.

Private Sub Combo1_click()
   othercontrol.SetFocus
End Sub

This works as I want if the user selects any item from the drop down list.  If the user clicks in the display area of the combobox and in effect re-selects the displayed item the focus remains on the combo box and the combo box has a blue background. I suppose the click event is not fired under this condition.

I found what I thought was the answer on the microsoft site in Q124058, but I cannot get it to work.

http://support.microsoft.com/support/kb/articles/Q124/0/58.asp

Any help is much appreciated.
Mitch.....
0
Comment
Question by:MitchSavage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6182859
you would have to hook the events of the combo box and see when it was closed.  I'll see if i can find some examples of this for you.  another route that is very good, and easy is to get the sheridan combo box.
0
 

Author Comment

by:MitchSavage
ID: 6183141
Thanks jrspano.

You might look at the link to MS in my question.  It should work, but doesn't.  Or, any other solution you can provide.  I don't want to add any third party controls because of the extra baggage.
Thanks
Regards
Mitch.....
0
 
LVL 5

Expert Comment

by:dtomyn
ID: 6183260
Haven't gone through the MS article yet, but my through my first look I notice that the SendMessage line should now look like:
Declare Function SendMessage Lib _
    "user32" Alias "SendMessageA" _
   (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long
...I am guessing this article was not written with 32-bit programming in mind?

Anyway, when I get a few minutes I will try the actual demo.
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 6

Accepted Solution

by:
sharmon earned 100 total points
ID: 6183396
Hello,

I tried out the MS demo and it was written for 16-bit windows.  I converted it over for you and everything is fine.  Here is the code.  Need a form with one combo box and one timer.

Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, _
  ByVal wParam As Long, lParam As Any) As Long

Const CB_GETDROPPEDSTATE = &H157

Private Sub Combo1_DropDown()
  Timer1.Interval = 1
  Timer1.Enabled = True
End Sub

Private Sub Form_Load()
  Combo1.AddItem "item# 1"
  Combo1.AddItem "item# 2"
  Combo1.AddItem "item# 3"
  Combo1.AddItem "item# 4"
End Sub

Sub Timer1_Timer()
  Dim lngStatus As Long
  lngStatus = SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0&, 0&)
 
  If lngStatus = 0& Then
    Debug.Print "DropDown list retracted!"
    Timer1.Enabled = False
  End If
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6183534
hearing...
0
 

Expert Comment

by:alicelknight
ID: 6184020
Mitch:
I'm not sure how your form works, but I use the following: put KeyPreview = True in form_load, use SendKeys to send a {TAB} character to tab through the controls, and set the tabindex for all controls on the form.  Then I put the following in the Lostfocus event:

Private Sub cboCategory1_LostFocus()
    Dim r As Long
   
    r = SendMessageLong(cboCategory1.hWnd, CB_SHOWDROPDOWN, False, 0)
End Sub

When the user selects an item by mouse or enter key, the focus immediately goes to the next control without having to set it.  You may not need to use sendkeys if you don't want to tab with the enter key.
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
0
 

Author Comment

by:MitchSavage
ID: 6184036
Thanks sharmon,
This works exactly as I want.  I'll be glad when I learn more about vb, until then thanks to you and the other experts I'm getting there.
Best Regards,
Mitch.....
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6184150
Your welcome, take care.

Shannon
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

696 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