kdeutsch
asked on
Items not removing from listbox
I have a list box that is populated with 2 different items depending on which options they choose. The first is just a alpha code called a uic and its value and text shown are the same.
the next is a name and for this I bind the name and ssn of a person. When I try to remove a UIC it works fine and removes from the listbox, but when I try to remove a name it does not work and the name stays. what can I do so that it removes, names or UIcs.
the next is a name and for this I bind the name and ssn of a person. When I try to remove a UIC it works fine and removes from the listbox, but when I try to remove a name it does not work and the name stays. what can I do so that it removes, names or UIcs.
'Code for the Uic Section of the program
Protected Sub txtUic_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUic.TextChanged
lbUic.Items.Add(HFID.Value)
txtUic.Text = String.Empty
End Sub
Protected Sub lbUic_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUic.SelectedIndexChanged
Dim Selected As String = lbUic.SelectedItem.ToString
Dim Value As String = lbUic.SelectedValue
lbUic.Items.Remove(Selected)
lbUic.Items.Remove(Value)
End Sub
'All the code for the Fill Personnel section of program
Protected Sub txtPersonnel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPersonnel.TextChanged
lbUic.Items.Add(New ListItem(txtPersonnel.Text, HFID.Value))
txtPersonnel.Text = String.Empty
End Sub
For Each item As ListItem In ListBox1.Items
If lstBox1.Items.FindByText(item.Text) IsNot Nothing Then
lstBox1.Items.Remove(lstBox1.Items.FindByText(item.Text))
End If
Next
ListBox1.ClearSelection()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
See On Planet-source-code.com
Just to complement my previous post, replace your code with:
Protected Sub lbUic_SelectedIndexChanged (ByVal sender As Object, ByVal e As System.EventArgs) Handles lbUic.SelectedIndexChanged
While lbUic.SelectedItems.Count > 0
lbUic.Items.Remove(myListB ox.Selecte dItems(0))
End While
End Sub
Protected Sub lbUic_SelectedIndexChanged
While lbUic.SelectedItems.Count > 0
lbUic.Items.Remove(myListB
End While
End Sub
ASKER
All,
Ok got around to trying all these this morning,
mas_oz2003:
I could not get count after selecteditem as there is no selecteditems and no count for either one of them.
disrupt:
did not work
Medo3337:
Worked as advertised.
Ok got around to trying all these this morning,
mas_oz2003:
I could not get count after selecteditem as there is no selecteditems and no count for either one of them.
disrupt:
did not work
Medo3337:
Worked as advertised.
ASKER
thanks
listBox1.SelectionMode = SelectionMode.MultiExtende
You should remove with this code:
While lbUic.SelectedItems.Count > 0
lbUic.Items.Remove(myListB
End While