Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C# - How to Make the ComboBox ' Values Distinct (Unique)?
Posted

Don't put the same values in the Items list...

Exactly how you do that depends on you: we have no idea how you are loading your Combobox, so we can't really help!
 
Share this answer
 
Comments
Member 10866804 28-Jan-17 11:39am    
You should just say you're confused and not be so condescendingly rude. Hopefully you've matured some over the years.
Hi,
You may use the distinct in the sql select query too, but below is an example of how we can distinct a list in c#:
C#
using (SqlConnection conn = new SqlConnection("Your Connectionstring"))
               {
                   conn.Open();
                   SqlCommand cmd = new SqlCommand("Your select Query", conn);

                   SqlDataReader dr = cmd.ExecuteReader();

                   IList<string> listName = new List<string>();
                   while (dr.Read())
                   {
                       listName.Add(dr[0].ToString());
                   }
                   listName = listName.Distinct().ToList();
                   ComboBox1.DataSource = listName;
               }</string></string>
 
Share this answer
 

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