Hmmmm. If I understand you correctly you only want the user to be able to select a value from the listbox only once, is that correct? If this is correct you have a couple of options:
I might rewrite your original code something like:
Code:
Dim item as New ListItem
Dim dstval As String = ""
Dim distsel as Integer = 0
For Each item in lstDistrict.Items
If item.Selected Then
dstval += item.Value
lstDistrict.Items.Remove(item)
End If
Next
This will allow you to keep a distinct list of items the User has NOT selected. Alternatively you could put another listbox on your form and just move an item from your source list box to a temporary list box.
Code:
Dim item as New ListItem
Dim dstval As String = ""
Dim distsel as Integer = 0
For Each item in lstDistrict.Items
If item.Selected Then
dstval += item.Value
lstDistrictNew.Items.Add(item)
lstDistrict.Items.Remove(item)
End If
Next
and you would do the reverse if you wanted to move an item back to the source list box:
Code:
...
lstDistrict.Items.Add(item)
lstDistrictNew.Items.Remove(item)
I didn't test any of this but it should work for you without much problem.
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for:
Beginning Visual C# 2008
Professional Search Engine Optimization with ASP.NET
Professional IIS 7 and ASP.NET Integrated Programming
Wrox Blox: Introduction to Google Gears
Wrox Blox: Create Amazing Custom User Interfaces with WPF and .NET 3.0
================================================== =========