[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Detect when Combo Box Retracts

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
MitchSavage
Asked:
MitchSavage
1 Solution
 
jrspanoCommented:
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
 
MitchSavageAuthor Commented:
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
 
dtomynCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sharmonCommented:
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
 
Richie_SimonettiIT OperationsCommented:
hearing...
0
 
alicelknightCommented:
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
 
MitchSavageAuthor Commented:
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
 
sharmonCommented:
Your welcome, take care.

Shannon
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now