Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Avoid duplicate items in listbox

Author  Topic 

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-08-04 : 23:48:52
I have two list boxes. The one of the left has available numbers, and the right is what the user will build for "selected" numbers.
I can pull them over to the right "selected" side, and allow users to delete them from the right if they make a mistake.

What I want to do is NOT allow users to add duplicate values on the right side.

Thanks!

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-08-07 : 09:37:23
Hello!

I used this code, and it works to not allow duplicates if I stay on the selected item in the list box and try to click it multiple times:

Dim li As New ListItem
For Each li In LB1.Items
If li.Selected = True Then
If Not ListBox2.Items.Contains(li) Then
ListBox2.Items.Add(li)
End If
End If
Next

If I go to another list item, say the one directly below, the go back to the initial item, I can in fact add duplicates. Any ideas? I'll keep searching too.

Thanks!
Go to Top of Page

bubberz
Constraint Violating Yak Guru

289 Posts

Posted - 2006-08-07 : 09:53:08
It would help if I put the code in the right listbox.

works fine!

Thanks!
Go to Top of Page
   

- Advertisement -