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 multiple selection up or down in Visual Basic .NET
DescriptionThis example shows how to use buttons to slide a ListBox's multiple selection up or down in Visual Basic .NET.
KeywordsListBox, select, selection, SelectedItem, SelectedIndex, SetSelected, VB.NET
CategoriesVB.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.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated