Solved

Detect when Combo Box Retracts

Posted on 2001-06-12
8
223 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
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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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…
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…

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