• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

How can I bring up dropdown list of DBCombo using code?

As title.
I am looking for something like the CB_SHOWDROPDOWN message of a regular combobox.
0
leeal
Asked:
leeal
  • 8
  • 6
  • 2
  • +2
1 Solution
 
MikeP090797Commented:
I haven't tried, but I'm almost positive it CB_SHOWDROPDOWN will work, since dbcombo is a subclass of regular combo box
0
 
leealAuthor Commented:
It doesn't work. Here's the code I used, it works on Combo but not DBCombo:
-----
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_SHOWDROPDOWN = &H14F

Public Sub Combo_ShowDropDown(cboControl As Object)
    Dim r As Long
    r = SendMessageLong(cboControl.hWnd, CB_SHOWDROPDOWN, True, 0)
End Sub

Public Sub Command1_Click()
    Combo_ShowDropDown DBCombo1
End Sub

0
 
viktornetCommented:
Here is the right way =)

r = SendMessageLong(cboControl.hWnd, CB_SHOWDROPDOWN, 1, 0)

Hope this helps =)

Regards,
Viktor Ivanov
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!

 
MikeP090797Commented:
I hope you tested it before posting it as an answer, cause i did, and it didn't work
0
 
viktornetCommented:
Opps....something else....don't use SendMessageLong....Instead use SendMessage That's a lot better...

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

Hey I'm not a VB programmer, but I think it will work...try it with SendMessage
0
 
viktornetCommented:
Did anyone test this example??? . o O

Regards,
Viktor Ivanov
0
 
leealAuthor Commented:
Doesn't work...
0
 
viktornetCommented:
How about without using

r = SendMessage()

instead use

 SendMessage()

Does this work?

Regards,
Viktor Ivanov
0
 
viktornetCommented:
Try this......

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

Private Sub Combo1_GotFocus ()
      Const CB_SHOWDROPDOWN = &H14F
      Dim Tmp
      Tmp = SendMessage(Combo1.hWnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub

Hope this works! =)

Regards,
Viktor Ivanov
0
 
leealAuthor Commented:
No. It doesn't work.
btw, I don't think it's a syntax problem because it works on the regular combobox.
0
 
viktornetCommented:
Did you try the second example I gave you?

//Vik
0
 
viktornetCommented:
Let me see the code you are trying to pass..Don't write it again, just copy it from your code

//Vik
0
 
leealAuthor Commented:
It's here already. (the 2nd comment)
The only difference is that I call Combo_ShowDropDown from DBGrid1_ButtonClick event instead of Command1_Click event.
0
 
mcixCommented:
leeal,

Are you running VB 5 with SP3?
0
 
viktornetCommented:
In that case I think that something is wrong with the DB control not with code

Regards,
Viktor Ivanov
0
 
leealAuthor Commented:
Yes, I am using SP3.
0
 
jsuperCommented:
Instead of worrying about all of the Send message API stuff, why don't you just use the sethocus and sendkey commands?  I've tried it out, and it works like a charm.  Just insert the following two lines when you want to force the DBCombo to drop down.

    DBCombo1.SetFocus
    SendKeys ("%{DOWN}"), True

Good Luck.
0
 
leealAuthor Commented:
Thanks, jsuper.
0

Featured Post

Technology Partners: 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!

  • 8
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now