Results 1 to 3 of 3

Thread: ListBox, ComboBox Horizontal Scroll: Simple Solution

  1. #1
    100 Club KevinBarnett's Avatar
    Join Date
    2001-10
    Location
    Pretoria, South Africa
    Posts
    119
    Login to Give a bone
    0

    Cool ListBox, ComboBox Horizontal Scroll: Simple Solution

    Hi Gang,

    Many developers probably know this little trick already. In case you dont, here it is.

    There is no horizontal scroll property for the ListBox and ComboBox form controls. If you want to have a horizontal scroll change the value of the ColumnWidths property to a value larger that the width of your control. For example, if the Width is 120, set the ColumnWidths to 350.

    Have a great day,

    Kevin.

  2. #2
    100 Club
    Join Date
    2000-11
    Location
    Adelaide, South Australia
    Posts
    116
    Login to Give a bone
    0

    Default Re: ListBox, ComboBox Horizontal Scroll: Simple Solution

    Hi Kevin,

    Here is a little extra info for you. You can actually make the scrollbar go exactly to the length of the longest item in the listbox. I achieve it by having a Textbox with the Visible property set to false and the Autosize property set to true and with the same font settings as the listbox. I get the value of the first item in the listbox and set the textbox with this value then set the columnwidth of the listbox to the width of the textbox. I then loop all items in the listbox setting the value of the textbox and if the textbox width is greater than the listbox's columnwidth I update it. Here is my code for a listbox called lstBatch and textbox called txtListScroll that I run after the listbox gets updated.

    Regards - Nathan

    Code:
     Private Sub SetScroll()
     Dim intListCount As Integer
     Dim intCount As Integer
     intListCount = lstBatch.ListCount
     If intListCount <> 0 Then
     	txtListScroll = lstBatch.list(0)
     	lstBatch.ColumnWidths = txtListScroll.Width
     End If
     intCount = 0
     While intCount <> intListCount
     	txtListScroll = lstBatch.list(intCount)
     	If lstBatch.ColumnWidths < txtListScroll.Width & " pt" Then
     		lstBatch.ColumnWidths = txtListScroll.Width
     	End If
     	intCount = intCount + 1
     Wend
     End Sub

  3. #3
    100 Club KevinBarnett's Avatar
    Join Date
    2001-10
    Location
    Pretoria, South Africa
    Posts
    119
    Login to Give a bone
    0

    Default Re: ListBox, ComboBox Horizontal Scroll: Simple Solution

    Thanks Nathan. Its adding tips like this that really make this Forum useful.

    Have a great day,

    Kevin.

Similar Threads

  1. No Horizontal Scroll Bar
    By tperson643298 in forum AutoCAD Mechanical - General
    Replies: 2
    Last Post: 2014-08-11, 07:33 PM
  2. 2013: Revit, Point Clouds - is there a simple surface or mesh solution?
    By t.eugene.lee285564 in forum Revit Architecture - General
    Replies: 0
    Last Post: 2013-08-11, 11:57 AM
  3. Remove an Item from a ComboBox
    By DW2Whittle in forum VBA/COM Interop
    Replies: 3
    Last Post: 2009-08-05, 12:04 AM
  4. Reference Excel Spread sheet in a userform combobox
    By mikeosborne in forum VBA/COM Interop
    Replies: 3
    Last Post: 2009-04-30, 06:22 PM
  5. Can you disable the horizontal and vertical scroll bars
    By AP23 in forum Revit - Hardware & Operating Systems
    Replies: 8
    Last Post: 2008-03-26, 07:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •