Number of visible items in listbox control 
Author Message
 Number of visible items in listbox control

Hello,

Is it possible to change the number of visible items (without having to
scroll) on a listbox control?

Any help would be great.

Mark



Thu, 20 Oct 2005 04:57:06 GMT  
 Number of visible items in listbox control
Hi Mark. The first answer would be "make it bigger" but that seems a little
too obvious doesn't it? Do I take it that you don't really mean a listbox
control at all, but a dropdown list style combobox? In which case I'm not
sure you can ....

Rob


Quote:
> Hello,

> Is it possible to change the number of visible items (without having to
> scroll) on a listbox control?

> Any help would be great.

> Mark



Thu, 20 Oct 2005 06:24:06 GMT  
 Number of visible items in listbox control
Yes Rob, I always mix them up!! Ofcourse I mean the combobox. There are so
many items available without scrolling. I use them for a time registration
app. and they want to be able to pick 8 hours without having to scroll. Only
the numbers 0 to 7 are visible without scrolling :-(


Quote:
> Hi Mark. The first answer would be "make it bigger" but that seems a
little
> too obvious doesn't it? Do I take it that you don't really mean a listbox
> control at all, but a dropdown list style combobox? In which case I'm not
> sure you can ....

> Rob



> > Hello,

> > Is it possible to change the number of visible items (without having to
> > scroll) on a listbox control?

> > Any help would be great.

> > Mark



Thu, 20 Oct 2005 06:35:19 GMT  
 Number of visible items in listbox control
Well in which case, sorry, but my second answer is "I've no idea" - perhaps
someone else knows of a way.

(Of course, if 8 hours is the most common selection you could always make it
the default by setting the ListIndex in advance. That way they wouldn't
usually have to touch the box at all.)

Rob


Quote:
> Yes Rob, I always mix them up!! Ofcourse I mean the combobox. There are so
> many items available without scrolling. I use them for a time registration
> app. and they want to be able to pick 8 hours without having to scroll.
Only
> the numbers 0 to 7 are visible without scrolling :-(



> > Hi Mark. The first answer would be "make it bigger" but that seems a
> little
> > too obvious doesn't it? Do I take it that you don't really mean a
listbox
> > control at all, but a dropdown list style combobox? In which case I'm
not
> > sure you can ....

> > Rob



> > > Hello,

> > > Is it possible to change the number of visible items (without having
to
> > > scroll) on a listbox control?

> > > Any help would be great.

> > > Mark



Thu, 20 Oct 2005 06:56:29 GMT  
 Number of visible items in listbox control

Quote:
> Yes Rob, I always mix them up!! Ofcourse I mean the combobox. There
are so
> many items available without scrolling. I use them for a time
registration
> app. and they want to be able to pick 8 hours without having to
scroll. Only
> the numbers 0 to 7 are visible without scrolling :-(

As for changing the number of lines displayed in a ComboBox, consider
the following code which allows you to modify the number of items
displayed...

Put (paste) the following declarations and procedure in a Module
(Project/AddModule from VB's menu):

Quote:
>>>>>Start Of Paste<<<<<

Private Declare Function SendMessageLong _
        Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam 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

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 Const CB_GETITEMHEIGHT = &H154

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Type POINTAPI
  x As Long
  y As Long
End Type

Public Sub SetComboBoxHeight(ComboBoxIn As ComboBox, _
                             NumberOfItemsTall As Long)
  Dim Point As POINTAPI
  Dim Rectangle As RECT
  Dim ComboBoxWidth As Long
  Dim NewComboBoxHeight As Long
  Dim EditAreaHeight As Long
  Dim OldScaleMode As Long
  Dim ListAreaHeight As Long
  ComboBoxWidth = ComboBoxIn.Width \ Screen.TwipsPerPixelX
  ListAreaHeight = SendMessageLong(ComboBoxIn.hwnd, _
                                   CB_GETITEMHEIGHT, 0, 0)
  EditAreaHeight = SendMessageLong(ComboBoxIn.hwnd, _
                                   CB_GETITEMHEIGHT, -1, 0)
  NewComboBoxHeight = ListAreaHeight * NumberOfItemsTall + _
                      2 * EditAreaHeight
  GetWindowRect ComboBoxIn.hwnd, Rectangle
  Point.x = Rectangle.Left
  Point.y = Rectangle.Top
  ScreenToClient ComboBoxIn.Container.hwnd, Point
  MoveWindow ComboBoxIn.hwnd, Point.x, Point.y, _
             ComboBoxWidth, NewComboBoxHeight, True
End Sub

Quote:
>>>>>End Of Paste<<<<<

Although you can specify less than eight items, you will get eight which
seems to be the minimum number of items displayable. Below is an example
showing a combo box being reset to the number contained in a text box.

SetComboBoxHeight  Combo1, CLng(Text1.Text)

Rick - MVP



Thu, 20 Oct 2005 14:28:52 GMT  
 Number of visible items in listbox control
Thanks Rick, I'll try it!

Mark


Quote:
> > Yes Rob, I always mix them up!! Ofcourse I mean the combobox. There
> are so
<<SNIP>>
> Although you can specify less than eight items, you will get eight which
> seems to be the minimum number of items displayable. Below is an example
> showing a combo box being reset to the number contained in a text box.

> SetComboBoxHeight  Combo1, CLng(Text1.Text)

> Rick - MVP



Mon, 24 Oct 2005 05:36:38 GMT  
 Number of visible items in listbox control
This looks good!! Thanks. I'm gonna try it!

Mark

Quote:
> As for changing the number of lines displayed in a ComboBox, consider
> the following code which allows you to modify the number of items
> displayed...

> Put (paste) the following declarations and procedure in a Module
> (Project/AddModule from VB's menu):

> >>>>>Start Of Paste<<<<<

<<SNIP>>

> >>>>>End Of Paste<<<<<

> Although you can specify less than eight items, you will get eight which
> seems to be the minimum number of items displayable. Below is an example
> showing a combo box being reset to the number contained in a text box.

> SetComboBoxHeight  Combo1, CLng(Text1.Text)

> Rick - MVP



Sun, 30 Oct 2005 04:32:24 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Datacombo: setting the number of visible items without scrolling

2. number of visible rows in listbox

3. Listbox item's array number

4. maximum allowable number of items in dropdown listbox

5. Q:How to get the number of lines visible in rich textbox control

6. Move ListBox items to another ListBox

7. Listbox with single character item corrupts item?

8. populating vb.net listbox from selected items of another listbox

9. Listbox items: copy to another listbox, but randomize their order

10. Controlling Selected Items in a MultiSimple ListBox

11. User Controls as Items in a Listbox

12. Could not remove item from listBox WinForm control

 

 
Powered by phpBB® Forum Software