How to control the number it items in a combo box dropdown list? 
Author Message
 How to control the number it items in a combo box dropdown list?

Hi,

I need to find out how to control the number of visible items in the
dropdown list of a standard VB5 combobox dropdown list.  I have a total of
12 items I need to display and I want to get rid of the vertical scrollbar
if possible.

Any help you could give me would be greatly appreciated.

  Thanks




Sun, 03 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Quote:

>I need to find out how to control the number of visible items in the
>dropdown list of a standard VB5 combobox dropdown list.  I have a total of
>12 items I need to display and I want to get rid of the vertical scrollbar
>if possible.

Here are the routines you need.

Frank Carr

=============================================================

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 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

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

Public Sub SetComboListAreaSize(objForm As Form, cboCombo As ComboBox)
'
' Makes the dropdown area of a combo box larger
'
    Dim pt As POINTAPI
    Dim rec As RECT
    Dim iItemWidth As Integer
    Dim iItemHeight As Integer
    Dim iOldScaleMode As Integer
    Dim nRet As Variant

    'Change the Scale Mode on the form to Pixels.
    iOldScaleMode = objForm.ScaleMode
    objForm.ScaleMode = vbPixels

    'Set the Width and new Height of the combo box.
    iItemWidth = cboCombo.Width
    iItemHeight = objForm.ScaleHeight - cboCombo.Top - 5
    objForm.ScaleMode = iOldScaleMode

    'Get the coordinates relative to the screen,
    nRet = GetWindowRect(cboCombo.hwnd, rec)
    pt.x = rec.Left
    pt.Y = rec.Top

    'then the coordinates relative to the form.
    nRet = ScreenToClient(objForm.hwnd, pt)

    'Finally, resize the combo box.
    nRet = MoveWindow(cboCombo.hwnd, pt.x, pt.Y, iItemWidth, iItemHeight, 1)

End Sub

=============================================================



Sun, 03 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Hey Frank-
    Muchos thank-yous!!! I've been trying to figure that
one out for a while.
Joe
--
***********************************************************

Microsoft Developer MVP- Visual Basic
VB geek at large. (Well, not that large!)
"He preaches well that lives well, quoth Sancho; that's
all the divinity I understand." Miguel de Cervantes
**********************************************************


Quote:

>>I need to find out how to control the number of visible items in the
>>dropdown list of a standard VB5 combobox dropdown list.  I have a total of
>>12 items I need to display and I want to get rid of the vertical scrollbar
>>if possible.

>Here are the routines you need.

>Frank Carr

>=============================================================

>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 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

>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

>Public Sub SetComboListAreaSize(objForm As Form, cboCombo As ComboBox)
>'
>' Makes the dropdown area of a combo box larger
>'
>    Dim pt As POINTAPI
>    Dim rec As RECT
>    Dim iItemWidth As Integer
>    Dim iItemHeight As Integer
>    Dim iOldScaleMode As Integer
>    Dim nRet As Variant

>    'Change the Scale Mode on the form to Pixels.
>    iOldScaleMode = objForm.ScaleMode
>    objForm.ScaleMode = vbPixels

>    'Set the Width and new Height of the combo box.
>    iItemWidth = cboCombo.Width
>    iItemHeight = objForm.ScaleHeight - cboCombo.Top - 5
>    objForm.ScaleMode = iOldScaleMode

>    'Get the coordinates relative to the screen,
>    nRet = GetWindowRect(cboCombo.hwnd, rec)
>    pt.x = rec.Left
>    pt.Y = rec.Top

>    'then the coordinates relative to the form.
>    nRet = ScreenToClient(objForm.hwnd, pt)

>    'Finally, resize the combo box.
>    nRet = MoveWindow(cboCombo.hwnd, pt.x, pt.Y, iItemWidth, iItemHeight,
1)

>End Sub

>=============================================================



Sun, 03 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Is it also possible to control the number of items when the combo box is in
the toolbar of an MDIForm?



Mon, 04 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Quote:

>Is it also possible to control the number of items when the combo box is in
>the toolbar of an MDIForm?

It depends on the type of toolbar being used. Assuming that your toolbar is
actually a picture box, you should be able to refer to it instead of a form.
It may require a little tinkering to get it right.

Frank Carr



Mon, 04 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Frank-
    It seems to work OK on MDI by using
Height/Width divided by TwipsPerPixelX/Y.
    Anyway, thanks again for the code.
Joe
--
***********************************************************

Microsoft Developer MVP- Visual Basic
VB geek at large. (Well, not that large!)
"He preaches well that lives well, quoth Sancho; that's
all the divinity I understand." Miguel de Cervantes
**********************************************************
PS- Please reply to the newsgroup- except in the
case of flames, insults, etc. (Don't bother.)

Quote:


>>Is it also possible to control the number of items when the combo box is
in
>>the toolbar of an MDIForm?

>It depends on the type of toolbar being used. Assuming that your toolbar is
>actually a picture box, you should be able to refer to it instead of a
form.
>It may require a little tinkering to get it right.

>Frank Carr




Mon, 04 Dec 2000 03:00:00 GMT  
 How to control the number it items in a combo box dropdown list?

Frank,  Joe:

Just wanted to thank you both for the help, the code works great.  That
little problem has been bugging me for quite a while.  It seems kind of
silly that such a simple thing is so difficult to implement.

Thanks again for all your help.

Jim



Tue, 05 Dec 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Set number of items in combo box dropdown

2. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

3. Dropdown List Box and Long List Items

4. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

5. Newbie: Set a combo box style(2)/Dropdown list to the first element in the list

6. Bold text on certain items in a combo box / list box

7. Default value for dropdown combo list box?

8. Combo Box - no2 dropdown list problem

9. Combo Box dropdown list

10. Combo Box / Dropdown list

11. Combo Box Dropdown List Width

12. COMBO BOX, STYLE : DROPDOWN LIST

 

 
Powered by phpBB® Forum Software