Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show last item in a listbox 1

Status
Not open for further replies.

CaKiwi

Programmer
Apr 8, 2001
1,294
US
How can I scroll a list box to show the last item?

CaKiwi
 
That didn't work for me, although something similar did work in VB6. This works but I hard coded the the number of visible lines in the list to be 7. Is there a way to determine this programatically?
Code:
        If lstInfo.Items.Count > 7 Then
            lstInfo.TopIndex = lstInfo.Items.Count - 7
        End If

CaKiwi
 
>>>That didn't work for me

Can you elaborate a little bit more on that. Rick's code should have worked. What's it doing on your system?

I don't recommend hard coding any type of selection like that because you will get unexpected results/error if the listbox ever changes
 
listbox.item gave a syntax error. I changed it to listbox.items and it had no effect on the appearance of the listbox

CaKiwi
 
Hmmm...I just through the following together real quick and it works fine.

Code:
Dim i As Int32 = 1
        Do While i < 10
            ListBox1.Items.Add("test" + i.ToString)
            i += 1
        Loop


        ListBox1.SelectedItem = ListBox1.Items(ListBox1.Items.Count - 2)
 
I just noticed you referenced scrolling also. I changed 10 to 40 to cause scroll bars and it scrolled to the item requested. Also, the 2 is in the code because I was testing differences. The last item is -1 from the count.
 
Thanks guys, I used
Code:
Me.ListBox1.TopIndex = Me.ListBox1.Items.Count - 1
and it worked fine

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top