Monday, 10 March 2014

Move Items up and down in Listbox


 
To move Items up and down in a listbox use the following code.
 
'Make sure our item is not the first one on the list.


'Move down    
If ListBox1.SelectedIndex > 0 Then

        Dim I = ListBox1.SelectedIndex - 1
        ListBox1.Items.Insert(I, ListBox1.SelectedItem)

        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)

        ListBox1.SelectedIndex = I
    End If


 

'Move down

    'Make sure our item is not the last one on the list.

    If ListBox1.SelectedIndex < ListBox1.Items.Count - 1 Then

       'Insert places items above the index you supply, since we want

       'to move it down the list we have to do + 2

        Dim I = ListBox1.SelectedIndex + 2

        ListBox1.Items.Insert(I, ListBox1.SelectedItem)

        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
        ListBox1.SelectedIndex = I - 1

    End If
Code taken from Dreamincode.net

No comments:

Post a Comment

Chrome 138 the last supported

Chrome 138 the last supported  Hey Everyone, Chrome 138 is the last version of Chrome that will support Android 8.0 (Oreo) and Android 9.0 (...