in form1 i have two listboxs listbox1 listbox2 loadbutton and savebutton

this code will write listbox1.selecteditem into a txt file and loadbutton will load info

in listbox2 but i want when i click loadbutton it check if that item is already exist in

listbox2 , if not so write selected item from listbox1 and if that item is already exist in listbox2 then do not save it (msg"this item is already exist in listbox2")

but this is not work well

Dim wri As New IO.StreamWriter("e:\test.txt", True)

    If ListBox2.ToString.Contains(ListBox1.Items.Item) Then ' or ListBox1.SelectedItem ? ' not work i tried more  ListBox2.ToString.CompareTo(ListBox1.SelectedItem) not work ):

        MsgBox("this item is already in listbox2")

        wri.WriteLine(ListBox1.SelectedItem, True)

    End If



If listBox2.Items.Contains(listBox1.SelectedItem.ToString) Then
    MessageBox.Show("This item is in listbox 2.")
End If
Be a part of the DaniWeb community

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