7
Answers

WPF listbox control

Avuya Mxoli

Avuya Mxoli

12y
3.1k
1
Hi all,

I have 2listboxes and two buttons. I am trying to move items between these listboxes using buttons. I want to avoid adding the same items more than once to any of the listboxes and here is what I am using which is not working. It just keeps adding and ignores the if statement.

if(listbox2.Items.Contains(listbox1.Items) == true)
{
MessageBox.Show("Items already added");
}
else
{
foreach(var item in listbox1.Items)//Adds ALL items that are in the listbox
{
listbox2.Items.Add(item);
}

Answers (7)