【发布时间】:2012-10-09 23:31:29
【问题描述】:
我在 C# 中创建一个自动建议/完整文本框,我点击下面的链接,但文本框没有显示建议
How to create autosuggest textbox in windows forms?
//-------- Get all distinct description -----------------------------
OleDbCommand command = new OleDbCommand(Queries.qry16, Connection);
OleDbDataReader reader = command.ExecuteReader();
//--------- Storing ------------------------------------
while (reader.Read())
{
namesCollection.Add(reader.GetValue(0).ToString());
}
//----------- Close after use ---------------------------------------
reader.Close();
//----------- Set the auto suggestion in description box ------------
descriptionBox.AutoCompleteMode = AutoCompleteMode.Suggest;
descriptionBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
descriptionBox.AutoCompleteCustomSource = namesCollection;
这是我的代码,它在 winform 的加载函数中。 nameCollection 初始化在构造函数中...请帮助使其正常工作。
我正在编辑我的帖子而不是创建新帖子...我已经在单行文本框中尝试了我自己的代码并且它有效。现在我想在多行中使用相同的内容...对于研究,我在 Google 上搜索了 2 天以上,尝试了不同的代码(一个具有智能感知的代码),但它不能作为文本框中的自动建议。谁能给我建议将整个过程编码为多行..谢谢。
【问题讨论】:
-
当您将
namesCollection指定为数据源时,您确定它实际上包含任何条目吗? -
私有 AutoCompleteStringCollection namesCollection;这就是我用来收集名字的东西
-
其实我发现了问题,文本框是多行而不是单行
标签: c# winforms autocomplete