Horizontal scrollbar in a listbox.

Discussion in 'AutoCAD' started by ntaylor, Sep 10, 2003.

  1. ntaylor

    ntaylor Guest

    Previously I haven't been able to have a horizontal scrollbar in a listbox on a VBA form. In attempting to add one using the win32 API I noticed that the listbox is now adding its own but it is not getting the length correct (AutoCAD 2004). My attempt to add the scrollbar is failing but it works fine in VB5 where the listbox is not adding it's own. This is my code:

    Option Explicit Private Declare Function GetFocus Lib "user32" () As Long Private Declare Function AddScrollBar Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    Private Sub UserForm_Activate() Dim hWnd As Long Dim wParam As Long ListBox1.SetFocus hWnd = GetFocus() ListBox1.AddItem "Test Item For Vertical Scrollbar" wParam = 200 'this should be automatically set to the width of the longest item Call AddScrollBar(hWnd, &H194, wParam, 0) End Sub

    Has anyone had similar problems?
    Does anyone know how to get a horizontal scrollbar working correctly?
    Regards - Nathan
     
    ntaylor, Sep 10, 2003
    #1
  2. ntaylor

    ntaylor Guest

    Thanks Wayne, Although the DoEvents did not help.
    With out trying to add the scrollbar the listbox adds its own if necessary. The problem is that the scrollbar is too short. If I try to add the scrollbar with my code it makes absolutely no difference. I am as certain as I can be that it is the correct hWnd. I think because it already has a scrollbar is the reason my code doesn't work. I hope this is clear enough.
    Regards - Nathan
     
    ntaylor, Sep 10, 2003
    #2
  3. ntaylor

    ntaylor Guest

    1. With out trying to add the scrollbar the listbox adds its own if necessary.
    2. The problem is that the scrollbar is too short.
    3. If I try to add the scrollbar with my code it makes absolutely no difference.
    4. I am as certain as I can be that it is the correct hWnd.
    5. I think because it already has a scrollbar is the reason my code doesn't work.
     
    ntaylor, Sep 10, 2003
    #3
  4. ntaylor

    joesu Guest

    Set the ColumnWidth property to be at least 1 greater than the ListBox Width property. This forces a HSB to appear. I don't believe it can be done through the Windows API.

    Joe
    --
     
    joesu, Sep 10, 2003
    #4
  5. ntaylor

    ntaylor Guest

    Thanks Joe, Works perfectly & makes perfect sense.
    Now to my second listbox question.
    I had this code to get the width of the text of an item in a listbox.
    Form1.TextWidth(List1.List(0))
    This worked for VB5 but not VBA. How can I get this width with VBA?
    Regards - Nathan
     
    ntaylor, Sep 11, 2003
    #5
  6. ntaylor

    wivory Guest

    Not sure that you can. Perhaps if you explain why you want to get that...
      
    Regards
      
    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Sep 11, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.