Solved

Detect when Combo Box Retracts

Posted on 2001-06-12
8
225 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

809 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