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;)

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.

@Oxiegen i get an error with this one lv.Items Untitled61

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.