?
Solved

Detect when Combo Box Retracts

Posted on 2001-06-12
8
Medium Priority
?
231 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
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 6

Accepted Solution

by:
sharmon earned 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

752 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