0

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")
    Else

        wri.WriteLine(ListBox1.SelectedItem, True)

    End If

    wri.Close()
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Mitja Bonca
0

try:

If listBox2.Items.Contains(listBox1.SelectedItem.ToString) Then
    MessageBox.Show("This item is in listbox 2.")
End If
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.