Hi there
How can I search a listbox with the selected item from a combobox, and if it was found to already exist in the listbox to overwrite the item with out making a new line in the listbox
:confused:
Printable View
Hi there
How can I search a listbox with the selected item from a combobox, and if it was found to already exist in the listbox to overwrite the item with out making a new line in the listbox
:confused:
VB Code:
Private Sub ComboBox1_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectionChangeCommitted If ComboBox1.SelectedItem Is Nothing Then Exit Sub If Not ListBox1.Items.Contains(ComboBox1.SelectedItem) Then ListBox1.Items.Add(ComboBox1.SelectedItem) End If End Sub
If it exists then there is no need to overwrite it since it is the same. If you mean that only one part matches then you'll have to give more information about what you are using as items, otherwise the above should work.
Actually I just reread your post and what I posted is a little bit different. It will add the combo.SelectedItem to the listbox if it does NOT exist in the listbox already.