Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Vb.net - scroll to bottom of listbox

Posted on 2014-02-25
4
Medium Priority
?
1,429 Views
Last Modified: 2014-02-25
Once a list box items list is bigger than display, it gets pushed to bottom and last item added is not visible.  You have to scroll the listbox manually.

How do I make the listbox to scroll to bottom of list with code?

And is there a way when adding items to the listbox, it pushes the previous item down and put current item at top?
0
Comment
Question by:keith1001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 1000 total points
ID: 39887055
To add to the top of the list, use the insert method. For example,

ListBox1.Items.Insert(0, "My Item")

That will insert the item at the top.
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 1000 total points
ID: 39887069
Add to and scroll to the bottom:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Static cnt As Integer = 0
        cnt = cnt + 1
        ListBox1.Items.Add("Item #" & cnt)
        ListBox1.SelectedIndex = ListBox1.Items.Count - 1
    End Sub

Open in new window


Add to and scroll to the top:
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Static top As Integer = 0
        top = top + 1
        ListBox1.Items.Insert(0, "Top #" & top)
        ListBox1.SelectedIndex = 0
    End Sub

Open in new window

0
 
LVL 14

Expert Comment

by:quizwedge
ID: 39887072
For the second half, it's a bit more complex. You can either select an element further down on the list and it should scroll or you can simulate a scroll. I haven't done that, but there's a blog post about how to do it in C# at http://umaranis.wordpress.com/2013/10/13/programmatically-scroll-listbox-in-net-windows-forms-c/ You need to use the SendMessage API call (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx)
0
 

Author Closing Comment

by:keith1001
ID: 39887166
Thanks guys for quick response and answers!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question