Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2006, 09:14 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default Standard Dropdown Combo box

I have a standard dropdown combo box, and I would like to be able to make the dropdown list longer. It defaults at 8, and I can't figure out how to do it.

Thanks in advance,

Kevin

dartcoach
__________________
dartcoach
 
Old November 7th, 2006, 04:07 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Change the Length property (if I remember right).

An HTML dropdown cannot be changed (as far as I know; I sure tried hard to).
 
Old November 7th, 2006, 05:07 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For VB6, as far as I have ever known, you need to make use of the windows api.
A good example of this can be seen at http://vbnet.mvps.org - look for the pages on combo api and you'll find the solution.

In VB.NET / C# the combo box control has a MaxDropDownItems property that does this nicely... of course I assume you are working with VB6

Woody Z http://www.learntoprogramnow.com
 
Old November 7th, 2006, 06:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here is the link (ps: even though the name of the site is vbnet, the code is for vb6)

http://vbnet.mvps.org/code/comboapi/comboheight.htm
 
Old November 7th, 2006, 10:13 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

thanks all! I've got quite a few combo boxes in my application and the code from your link, seems to be quite a lot of code addition for simply giving a user 20 entries vs 8.

Thanks for the help though!

Kevin

dartcoach
 
Old November 7th, 2006, 11:07 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by dartcoach
 thanks all! I've got quite a few combo boxes in my application and the code from your link, seems to be quite a lot of code addition for simply giving a user 20 entries vs 8.
 It might seem like a lot of code - and that was the beauty of VB in the first place: You could do a lot with just a little code, and without much knowledge of the more complicated things. The only drawback was that if MS didn't provide the exact functionality you needed, you had to learn a bit about the deeper stuff. I this case, it is a few API calls. However, the main api code only needs to be added to your code in one place to be used from everywhere, and if you really want to do it right, you can add a new class to provide the extended functionality you want for your combo. As time goes by, you add to the class and build up a little library of features you have found useful.

Woody Z http://www.learntoprogramnow.com
 
Old November 8th, 2006, 03:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the internet is great, but you have to take the code as-is
for this reason I never use downloaded code unless I understand every single line of code (if something goes wrong, it is the only safety net)
In this particolar case, the code was just an example, but all the logic can be easily wrapped in a single bas module.
Create a new bas module, and cut and paste this code into it:

Code:
Option Explicit

Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETITEMHEIGHT = &H154

Private Type POINTAPI
   x As Long
   y As Long
End Type
Private Type RECT
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

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

Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
   ByVal x As Long, ByVal y As Long, _
   ByVal nWidth As Long, _
   ByVal nHeight As Long, _
   ByVal bRepaint As Long) As Long

Private Declare Function GetWindowRect Lib "user32" _
  (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function ScreenToClient Lib "user32" _
  (ByVal hWnd As Long, lpPoint As POINTAPI) As Long


Public Sub SetComboMenu(frx As Form, cb As ComboBox, ByVal numItemsToDisplay As Long)

   Dim pt As POINTAPI
   Dim rc As RECT
   Dim cWidth As Long
   Dim newHeight As Long
   Dim oldScaleMode As Long
   Dim itemHeight As Long

   If numItemsToDisplay > cb.ListCount Then
        numItemsToDisplay = cb.ListCount
    End If

   oldScaleMode = frx.ScaleMode
   frx.ScaleMode = vbPixels

   cWidth = cb.Width

   itemHeight = SendMessage(cb.hWnd, CB_GETITEMHEIGHT, 0, ByVal 0)
   newHeight = itemHeight * (numItemsToDisplay + 2)

   Call GetWindowRect(cb.hWnd, rc)
   pt.x = rc.Left
   pt.y = rc.Top
   Call ScreenToClient(frx.hWnd, pt)

   Call MoveWindow(cb.hWnd, pt.x, pt.y, cb.Width, newHeight, True)
'   Call SendMessage(cb.hWnd, CB_SHOWDROPDOWN, True, ByVal 0)

   frx.ScaleMode = oldScaleMode

End Sub
that is basically the same code of the article, without the comments, and alla parameters are passed to a single method

In your form load event, you just have to add:

SetComboMenu Me, Combo1, 32
SetComboMenu Me, Combo2, 32
SetComboMenu Me, Combo3, 32

where 32 is the maximum of items displayd in the menu (you can change it as you wish)

NOW, they are really not many lines of code...
 
Old November 8th, 2006, 09:36 PM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 471
Thanks: 0
Thanked 1 Time in 1 Post
Default

marcostraf,

Perfect! Thanks very much!

Kevin

dartcoach
 
Old November 8th, 2006, 10:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you are welcome!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate a text box from a combo box value dnf999 Access VBA 7 February 6th, 2012 02:24 PM
Combo box to display items from parent combo box Gini Visual Studio 2008 0 June 18th, 2008 12:30 AM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Combo box choice creating filtered combo box stevensj5 Access 11 September 13th, 2007 11:33 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.