C# - 如何使ComboBox的值不同(唯一)? [英] C# - How to Make the ComboBox ' Values Distinct (Unique)?
本文介绍了C# - 如何使ComboBox的值不同(唯一)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C# - 如何使ComboBox的值不同(唯一)?
C# - How to Make the ComboBox ' Values Distinct (Unique)?
推荐答案
不要在Items列表中放置相同的值...
你究竟是怎么做的取决于你:我们不知道你是如何加载你的Combobox的,所以我们无法提供帮助!
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!
您好,
您可以在sql
<$ c中使用distinct
$ c>选择查询,但下面是我们如何distinct c#中列表的示例:
Hi,
You may use thedistinct
in thesql
select
query too, but below is an example of how we candistinct
a list in 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>
这篇关于C# - 如何使ComboBox的值不同(唯一)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文