|
-
Aug 25th, 2007, 09:24 PM
#1
Thread Starter
Addicted Member
[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...
-
Aug 25th, 2007, 09:29 PM
#2
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
-
Aug 25th, 2007, 10:24 PM
#3
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.
-
Aug 25th, 2007, 10:32 PM
#4
Thread Starter
Addicted Member
Re: ListBox, bump new item into view ?
Perfect ! Just what I was looking for.... Thanks !
-
Aug 25th, 2007, 10:55 PM
#5
Re: ListBox, bump new item into view ?
 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.
-
Aug 26th, 2007, 02:46 AM
#6
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.
-
Aug 26th, 2007, 10:10 AM
#7
Re: [RESOLVED] ListBox, bump new item into view ?
 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
-
Aug 26th, 2007, 04:56 PM
#8
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|