这是我的FormLoad
-event 上的代码
SqlDataReader dReader;
SqlConnection conn = new SqlConnection(MyClass.GlobalConn());
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
if (radioName.checked==true)
{
cmd.CommandText = "select RTRIM(Person_name) from MyTable order by Person_name";
}
else
{
cmd.CommandText = "select RTRIM(Person_number) from MyTable order by Person_number";
}
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
{
while (dReader.Read())
namesCollection.Add(dReader[0].ToString());
}
else
{
MessageBox.Show("Data not found");
}
dReader.Close();
tPT.AutoCompleteMode = AutoCompleteMode.Suggest;
tPT.AutoCompleteSource = AutoCompleteSource.CustomSource;
tPT.AutoCompleteCustomSource = namesCollection;
conn.Close();
我想要两个选项来在输入文本框时填充自动完成文本框:
- 按名字
- 按编号
但是它不起作用。我已经在我的事件中尝试过这个TextChanged
,但没有运气。有人可以帮助我吗?