Results 1 to 8 of 8

Thread: [RESOLVED] ListBox, bump new item into view ?

  1. #1

    Thread Starter
    Addicted Member tcurrier's Avatar
    Join Date
    May 1999
    Location
    Northeastern Pa./USA
    Posts
    255

    Resolved [RESOLVED] ListBox, bump new item into view ?

    I have a ListBox that holds 5 lines of data. In my program, I add a line to the ListBox as certain events occur.

    When I go to add the 6th item to the ListBox, a scrollbar appears, but the 6th item doesn't show up at the bottom.

    For example, I want the ListBox to look like this when the 6th item is added:

    Item #2
    Item #3
    Item #4
    Item #5
    Item #6

    Thanks for any help...
    VB6 Enterprise SP4

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: ListBox, bump new item into view ?

    After you call the AddItem method, add this line:

    List1.ListIndex = List1.NewIndex

    If you just want the new item to be visible but not selected, add this line as well:

    List1.ListIndex = -1

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: ListBox, bump new item into view ?

    yes, as ellis says, that will scroll down to the selected index. If you don't like the fact you have to select text, there is an option in the listview control that does this.
    Code:
    listview1.listitems(18).ensurevisible
    this example would scroll the listbox until item 18 was visible but not move anything if it already was.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  4. #4

    Thread Starter
    Addicted Member tcurrier's Avatar
    Join Date
    May 1999
    Location
    Northeastern Pa./USA
    Posts
    255

    Re: ListBox, bump new item into view ?

    Perfect ! Just what I was looking for.... Thanks !
    VB6 Enterprise SP4

  5. #5
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: ListBox, bump new item into view ?

    Quote Originally Posted by Lord Orwell
    yes, as ellis says, that will scroll down to the selected index. If you don't like the fact you have to select text, there is an option in the listview control that does this.
    Code:
    listview1.listitems(18).ensurevisible
    this example would scroll the listbox until item 18 was visible but not move anything if it already was.
    Our answers apply to different controls. The OP asked about listboxes, though it's possible he meant listviews. Listboxes do not have ListItem objects, and so do not have an EnsureVisible method.

  6. #6
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: [RESOLVED] ListBox, bump new item into view ?

    Check out the TopIndex property for ListBoxes. It allows you to scroll the ListBox without selecting an item.

  7. #7
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: [RESOLVED] ListBox, bump new item into view ?

    Quote Originally Posted by Logophobic
    Check out the TopIndex property for ListBoxes. It allows you to scroll the ListBox without selecting an item.
    Nice tip, that's much better.

    For the OP, this reduces the logic to a single line:

    List1.TopIndex = List1.NewIndex

  8. #8
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: [RESOLVED] ListBox, bump new item into view ?

    yes. If you read my answer carefully, ellis dee you will see that i not only mentioned that my answer worked with a listview, but i said it was an alternative control if he didn't like his selection highlighted. But logophobic makes that point moot.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

Posting Permissions

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



Click Here to Expand Forum to Full Width