Private Sub cmdRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRemove.Click
If ListLeft.SelectedIndex < 0 Then
MsgBox("Please select an item", MsgBoxStyle.Exclamation, "Error")
Else
If ListLeft.Items.Count > 0 Then
ListRight.Items.Add(ListLeft.SelectedItem)
ListLeft.Items.Remove(ListLeft.SelectedItem)
End If
End If
End Sub
Date :
2011-04-22 06:13:59
By :
til
No. 2
Guest
Code (VB.NET)
'Move up
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Make sure our item is not the first one on the list.
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
End Sub
'Move down
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'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
End Sub