?
Solved

Vb.net - scroll to bottom of listbox

Posted on 2014-02-25
4
Medium Priority
?
1,375 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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