谢谢您的帮助!!我使用了你的建议并做了一些小改动,对我来说效果很好......
事实证明,唯一的问题是我的方法列表,一旦我改变它做一个List < String >事情变得更好。对于谁想知道,这是我的做法:
DAL层:
public List<string> LoadList()
{
List<string> tagsList = new List<string>();
using (SqlConnection connection = new SqlConnection(ADados.StringDeConexao))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT column FROM table";
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
if (!reader.IsDBNull(0))
tagsList.Add(reader.GetString(0));
}
reader.Close();
}
connection.Close();
return tagsList;
}
呈现层(事件 TextChanged):
PedidoBLL pedido = new PedidoBLL();
txtName.AutoCompleteMode = AutoCompleteMode.Suggest;
txtName.AutoCompleteSource = AutoCompleteSource.CustomSource;
AutoCompleteStringCollection popula = new AutoCompleteStringCollection();
popula.AddRange(pedido.LoadList().ToArray());
txtName.AutoCompleteCustomSource = popula;
在 BLL 层中,我只是调用并返回 DAL 方法 LoadList ...