I have 2 listboxes. The first one is loaded with data. I am loading the second listbox with data selected in the first listbox, using a command button. If I select only one item in the first list box, and click the button, the second listbox with show nothing, but if I select more than one item in the first listbox and click the button, then the second list box will populate correctly. I also remove the entry from the first listbox after it has been copied to the 2nd listbox. I also have a button that removes selected items from the 2nd listbox and copies it back to the first listbox and that button is working fine. I have the following code for my add button:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim i As Integer
'Dim myItem As String
'Start updating the list boxes
lstRelate.BeginUpdate()
lstSurvey.BeginUpdate()
'copy the selected items to the lstRelate listbox
For i = 0 To lstSurvey.Items.Count - 1
If lstSurvey.GetSelected(i) = True Then
lstRelate.Items.Add(lstSurvey.SelectedItem)
lstSurvey.SetSelected(i, False)
End If
Next
'remove the items shown in the relate listbox from the survey list box
For i = 0 To lstRelate.Items.Count - 1
lstSurvey.Items.Remove(lstRelate.Items(i))
Next
'stop updating the list boxes
lstSurvey.EndUpdate()
lstRelate.EndUpdate()
End Sub
I am using vb.net 2003 and the listbox is set to multi extended.
Anybody have any idea? I'm stumped.
Thanks.
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim i As Integer
'Dim myItem As String
'Start updating the list boxes
lstRelate.BeginUpdate()
lstSurvey.BeginUpdate()
'copy the selected items to the lstRelate listbox
For i = 0 To lstSurvey.Items.Count - 1
If lstSurvey.GetSelected(i) = True Then
lstRelate.Items.Add(lstSurvey.SelectedItem)
lstSurvey.SetSelected(i, False)
End If
Next
'remove the items shown in the relate listbox from the survey list box
For i = 0 To lstRelate.Items.Count - 1
lstSurvey.Items.Remove(lstRelate.Items(i))
Next
'stop updating the list boxes
lstSurvey.EndUpdate()
lstRelate.EndUpdate()
End Sub
I am using vb.net 2003 and the listbox is set to multi extended.
Anybody have any idea? I'm stumped.
Thanks.