0

hi
how do i set a listview to only add one item from a combobox?
example: when the combobox contains the items dog,cat,pig and when the user chooses pig it is added to the listview but when the user selects the pig again it must prompt that already added...

i have here a code for adding items in a listview:
Dim lv As ListViewItem = ListView1.Items.Add(ComboBox7.Text)
lv.SubItems.Add(ComboBox2.Text)
lv.SubItems.Add(ComboBox4.Text)
lv.SubItems.Add(ComboBox5.Text)
lv.SubItems.Add(ComboBox6.Text)
lv.SubItems.Add(TextBox2.Text)

i will really appreciate anyones help;)

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by jhedonghae
0

Iterate through the items in the ListView and check the .Text property if the selected item is already present.

For Each item As ListViewItem In lv.Items
    If item.SubItem(0).Text = <combobox>.SelectedItem Then
        MessageBox("The selected item is already added")
        Return
    End If
Next

item.SubItem(0) represents the very first column in the ListView.
Replace <combobox> with whatever name of the combobox you wish to check against.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.