+ Reply to Thread
Results 1 to 14 of 14

Hide listbox scrollbar

  1. #1
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Hide listbox scrollbar

    Hi all,
    I need to hide the scrollbar of a listbox so I can use my own modified control.
    I found an VB API that can do that but am having trouble adjusting it to Excel VBA.

    Please Login or Register  to view this content.

    Now I found that there is no .hwnd property in VBA and Application.hwnd should be able to replace it but in both cases (with or without the Application. part) I get a "method or data member not found" message.

    Can anyone help me sort this out?

    Much obliged
    Nick

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Hide listbox scrollbar

    Why go to all that trouble?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Hide listbox scrollbar

    Quote Originally Posted by royUK View Post
    Why go to all that trouble?
    I want to triger some code on a listbox scroll event. Since I couldn't find any way to do it with the listbox scrollbar I figured I'd just use a spinbutton to do the scrolling and triger the desired code with the SpinButton_SpinDown and SpinUp events.

    I'm open to suggestions.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Hide listbox scrollbar

    Still not clear why you need to capture the scroll but how about using a frame control, which has scroll event.
    Within the frame could be a listbox, although you will need to have could handling the scrolling of the frame when the list selection changes.
    Or you could use a label for each list item, again code would be needed to handle user input via keyboard and scrolling.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Hide listbox scrollbar

    Quote Originally Posted by Andy Pope View Post
    Still not clear why you need to capture the scroll but how about using a frame control, which has scroll event.
    Within the frame could be a listbox, although you will need to have could handling the scrolling of the frame when the list selection changes.
    Or you could use a label for each list item, again code would be needed to handle user input via keyboard and scrolling.
    Here's the deal. I've already completed the spin button, created a scrolling function and made it to exactly what I want. I just need a way to hide the scrollbar so it doesn't confuse people.

    Even if it's not with the API. I tried placing the spin button on top of the listbox but it is always sent to the back. I tried placing a frame on top of the listbox but it also gets sent to the back...

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Hide listbox scrollbar

    The does API for scrolling. It appears to have code to get the handle which would be needed to hide the scrollbar.
    http://www.xtremevbtalk.com/archive/.../t-178071.html

  7. #7
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Hide listbox scrollbar

    Quote Originally Posted by Andy Pope View Post
    The does API for scrolling. It appears to have code to get the handle which would be needed to hide the scrollbar.
    http://www.xtremevbtalk.com/archive/.../t-178071.html
    Hi Andy. Thanks for the tip. Sadly I'm only managing to get the handle for the entire userform and not the listbox. I'm a novice when it comes to API's.

    Please Login or Register  to view this content.

    I don't know how to use the FindWindow function for the listbox.
    I'd appreciate your help, only if you can spare the time, of course.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Hide listbox scrollbar

    On close look it seems that code is catching scrolling anywhere within the userform and applying it to the listbox.

    Trouble is vba userform controls are windowless and therefore have no handle to use in API routines.

    Without understanding the why it's hard to suggest alternatives

  9. #9
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Hide listbox scrollbar

    Got it. It's a rather crude solution but it works.
    Againg - "the why" is my attempt to have a simple on scroll event.
    The how - the spin button fulfills the function of the scrolbar and the scrollbar gets obscured with another narrow listbox - the only object you can place above other listboxes.

    I know, not very ellegant but it keeps things simple.

    Thanks for the help guys, especially you Andy

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Hide listbox scrollbar

    That's not the why. The why would be something like I have 3 listboxes and I want all 3 to scroll at once.

  11. #11
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Hide listbox scrollbar

    The listbox does appear to have a handle (or possibly whatever it is contained in does), but I'll be damned if I can get it to remove the scrollbars, using either the ShowScrollBar method or changing the window style with SetWindowLong.
    Remember what the dormouse said
    Feed your head

  12. #12
    Registered User
    Join Date
    06-11-2009
    Location
    Berlin
    MS-Off Ver
    Excel 2003
    Posts
    63

    Re: Hide listbox scrollbar

    Quote Originally Posted by romperstomper View Post
    The listbox does appear to have a handle (or possibly whatever it is contained in does), but I'll be damned if I can get it to remove the scrollbars, using either the ShowScrollBar method or changing the window style with SetWindowLong.
    Let me know if you find something

    @Andy - sorry, friend. No simple on scroll event for the scrollbar is enough of a reason for me.

  13. #13
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Hide listbox scrollbar

    I don't think it will work. The class name of the window is the same as that for the form area (and there doesn't appear to be a child window) so I don't think it's actually a window to the listbox itself.

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Hide listbox scrollbar

    Why the need to capture the scroll event. What would you do if you did have an event?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1