Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse buttons to slide a ListBox's selection up or down in Visual Basic .NET
DescriptionThis example shows how to use buttons to slide a ListBox's selection up or down in Visual Basic .NET.
KeywordsListBox, select, selection, SelectedItem, SelectedIndex, SetSelected, VB.NET
CategoriesVB.NET, Controls
 
To slide the selection up, see if the SelectedIndex property is greater than 0. If it is, subtract 1 from it.

To slide the selection down, see if the SelectedIndex property is less than the second largest item index. If it is, add 1 to it.

 
Private Sub btnUp_Click(...) Handles btnUp.Click
    If lstAnimals.SelectedIndex > 0 Then _
        lstAnimals.SelectedIndex -= 1
End Sub

Private Sub btnDown_Click(...) Handles btnDown.Click
    If lstAnimals.SelectedIndex < lstAnimals.Items.Count - _
        1 Then lstAnimals.SelectedIndex += 1
End Sub
 
For more information on programming in VB .NET, see my book Visual Basic 2005 Programmer's Reference.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated