AutoCompleteStringCollection treatmentCollection = new AutoCompleteStringCollection();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCeCommand cmdTreatment = new SqlCeCommand("select Treatment from NewPatient", con);
SqlCeDataReader readerTreatment = cmdTreatment.ExecuteReader();
if (readerTreatment.Read() == true)
{
while (readerTreatment.Read())
{
treatmentCollection.Add(readerTreatment["Treatment"].ToString());
}
}
comboBox2.AutoCompleteMode = AutoCompleteMode.Suggest;
comboBox2.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox2.AutoCompleteCustomSource = treatmentCollection;
if (con.State == ConnectionState.Open)
{
con.Close();
}
我希望 combobox2
应该只有不同的值。
组合框从 AutoCompleteStringCollection
类的 treatmentCollection
对象获取值
请帮帮我?
最佳答案
替换:
select Treatment from NewPatient
为此:
select distinct Treatment from NewPatient
关于c# - 从 AutoCompleteStringCollection c# 中删除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16276312/