Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have two comboBoxes which have some duplicate values, my problem is I need to compare tow comboBoxes and need to remove duplicate values in comboBox 1 only, here is a code which express how to remove duplicates in comparing one comboBox value. Please support me.

comboBox1.Items.AddRange(dt.AsEnumerable().Select(i => i.ItemArray[0]).Distinct().ToArray());
Posted
Comments
ZurdoDev 19-Nov-14 11:08am    
Does the code work?

This is one of those code issues that has many different ways of doing it and you'll end up spending more time trying to perfect it than if you just picked a way and did it.
abdulsafran 19-Nov-14 11:33am    
It's not working exactly, I just want to compare two combo box and remove duplicate values. That's all.

1 solution

Assuming you want to click a Button to update:
C#
private void RemoveCBDuplicates_Click(object sender, EventArgs e)
{
    var itms1 = TheFirstComboBox.Items;
    var itms2 = TheSecondComboBox.Items;

    foreach (var itm in itms2)
    {
        if(itms1.Contains(itm)) itms1.Items.Remove(itm);
    }
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Nov-14 15:47pm    
5ed.
—SA
abdulsafran 19-Nov-14 22:02pm    
Thank you very much BillWoodruff!!!
Member 12431701 15-Oct-18 3:18am    
Am receiving error as best overloaded methods has invalid arguments
BillWoodruff 15-Oct-18 8:22am    
The question is 4 years old. I suggest you post a new question with the code that the error occurs in. cheers, Bill
Member 12431701 31-Oct-19 8:38am    
thank you..it was helpful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900