Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have a list boxes List1 and List2 and I want to add selected item from List2 to List1. I do as follows.
List1
List2
List1.Items.Add(List2.SelectedItem);
How to avoid duplicating in List1 if the same item from List2 is being added?
if (List2.SelectedItem != null if (! List1.Items.Contains(List2.SelectedItem)) { List1.Items.Add(List2.SelectedItem); List2.Remove(List2.SelectedItem); }
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.