First let me explain my settings at the moment.
I have 2 listboxes on a form, which contain the same items (and in the same order).
I would like to know if and how I can move a selected item in one listbox and the second listbox moves the same item aswell (so they move in sync).
I can move the items in one listbox with the following code:
The moving up and down is being done by buttons.
Thanks for any respons
I have 2 listboxes on a form, which contain the same items (and in the same order).
I would like to know if and how I can move a selected item in one listbox and the second listbox moves the same item aswell (so they move in sync).
I can move the items in one listbox with the following code:
VB.NET:
Private Sub UpButton_Click(sender As System.Object, e As System.EventArgs) Handles UpButton.Click
Dim index As Integer = ListBox1.SelectedIndex
If index > 0 Then
Dim temp As String = ListBox1.SelectedItem
ListBox1.Items.RemoveAt(index)
ListBox1.Items.Insert(index - 1, temp)
ListBox1.SelectedIndex = index - 1
End If
End Sub
Private Sub DownButton_Click(sender As System.Object, e As System.EventArgs) Handles DownButton.Click
Dim index As Integer = ListBox1.SelectedIndex
If index <> -1 AndAlso index < ListBox1.Items.Count - 1 Then
Dim temp As String = ListBox1.SelectedItem
ListBox1.Items.RemoveAt(index)
ListBox1.Items.Insert(index + 1, temp)
ListBox1.SelectedIndex = index + 1
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim index As Integer = ListBox1.SelectedIndex
If index <> -1 Then
UpButton.Enabled = (index > 0)
DownButton.Enabled = (index < ListBox1.Items.Count - 1)
End If
End Sub
The moving up and down is being done by buttons.
Thanks for any respons