c# - 从 AutoCompleteStringCollection c# 中删除重复项

标签 c# windows winforms

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/

相关文章:

C#聚合函数定义解释

c# - 使用 Linq 和分组依据将数据表转换为对象

java - 从腻子中提取日志

c++ - 如何在 Windows Vista/7 中以编程方式控制文本输入面板 (TabTip.exe)

c# - 在属性网格中创建可扩展组?

c# - 需要一些关于 HashSet 工作原理的解释

c# - 无法使用 Datetime.ParseExact 转换日期时间字符串

python - 32 位 Windows 10 上的 Tensorflow : is not a supported wheel on this platform; package missing in current win-32 channels, 没有匹配的发行版

c# - 在 WinForms 应用程序中放置功能代码的位置

c# - 如何判断KeyCode是否为可打印字符