|
|
Title | Use buttons to slide a ListBox's multiple selection up or down in Visual Basic .NET |
Description | This example shows how to use buttons to slide a ListBox's multiple selection up or down in Visual Basic .NET. |
Keywords | ListBox, select, selection, SelectedItem, SelectedIndex, SetSelected, VB.NET |
Categories | VB.NET, Controls |
|
|
To slide the selections up, loop through the items and use SetSelected to give each item the same selected value as the one below it.
To slide the selections down, loop through the items and use SetSelected to give each item the same selected value as the above following it.
|
|
Private Sub btnUp_Click(...) Handles btnUp.Click
For i As Integer = 0 To lstAnimals.Items.Count - 2
lstAnimals.SetSelected(i, lstAnimals.GetSelected(i _
+ 1))
Next i
lstAnimals.SetSelected(lstAnimals.Items.Count - 1, _
False)
End Sub
Private Sub btnDown_Click(...) Handles btnDown.Click
For i As Integer = lstAnimals.Items.Count - 1 To 1 Step _
-1
lstAnimals.SetSelected(i, lstAnimals.GetSelected(i _
- 1))
Next i
lstAnimals.SetSelected(0, False)
End Sub
|
|
For more information on programming in VB .NET, see my book Visual Basic 2005 Programmer's Reference.
|
|
|
|
|
|