Solved

Vb.net - scroll to bottom of listbox

Posted on 2014-02-25
4
1,300 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 250 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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