Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox issues

Status
Not open for further replies.

tman72

Technical User
Jan 22, 2003
116
0
0
US
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.
 
Disregard -

The problem was a corrupt listbox. I deleted, closed the project and created a new listbox and all is working fine.

Thanks anyway.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top