Solved

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

Posted on 1998-08-23
18
348 Views
Last Modified: 2008-03-10
As title.
I am looking for something like the CB_SHOWDROPDOWN message of a regular combobox.
0
Comment
Question by:leeal
  • 8
  • 6
  • 2
  • +2
18 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1430534
I haven't tried, but I'm almost positive it CB_SHOWDROPDOWN will work, since dbcombo is a subclass of regular combo box
0
 
LVL 1

Author Comment

by:leeal
ID: 1430535
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1430536
Here is the right way =)

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

Hope this helps =)

Regards,
Viktor Ivanov
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1430537
I hope you tested it before posting it as an answer, cause i did, and it didn't work
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430538
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1430539
Did anyone test this example??? . o O

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:leeal
ID: 1430540
Doesn't work...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430541
How about without using

r = SendMessage()

instead use

 SendMessage()

Does this work?

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430542
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:leeal
ID: 1430543
No. It doesn't work.
btw, I don't think it's a syntax problem because it works on the regular combobox.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430544
Did you try the second example I gave you?

//Vik
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430545
Let me see the code you are trying to pass..Don't write it again, just copy it from your code

//Vik
0
 
LVL 1

Author Comment

by:leeal
ID: 1430546
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
 
LVL 4

Expert Comment

by:mcix
ID: 1430547
leeal,

Are you running VB 5 with SP3?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1430548
In that case I think that something is wrong with the DB control not with code

Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:leeal
ID: 1430549
Yes, I am using SP3.
0
 
LVL 1

Accepted Solution

by:
jsuper earned 100 total points
ID: 1430550
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
 
LVL 1

Author Comment

by:leeal
ID: 1430551
Thanks, jsuper.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

20 Experts available now in Live!

Get 1:1 Help Now