|
|
Title | Use buttons to slide a ListBox's selection up or down in Visual Basic .NET |
Description | This example shows how to use buttons to slide a ListBox's selection up or down in Visual Basic .NET. |
Keywords | ListBox, select, selection, SelectedItem, SelectedIndex, SetSelected, VB.NET |
Categories | VB.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.
|
|
|
|
|
|