<分区>
我有一个简单的表单,其中有 3 个文本框,如下图所示:
在 textchanged 事件上使用自动完成功能,我在 textbox1(人名)中显示来自数据库的数据。现在,如果您的用户从建议的项目中选择一个特定名称,我想根据 textbox1 的值自动填充数据库中的 textbox2 和 textbox3。 我应该怎么做?
文本框1的代码:
private void textBox1_TextChanged(object sender, EventArgs e)
{
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
SqlConnection con = new SqlConnection(@"***my connection string***");
con.Open();
SqlCommand cmnd = con.CreateCommand();
cmnd.CommandType = CommandType.Text;
cmnd.CommandText = "SELECT * FROM tblTicketDetail";
SqlDataReader dReader;
dReader = cmnd.ExecuteReader();
if (dReader.Read())
{
while (dReader.Read())
namesCollection.Add(dReader["ContactPerson"].ToString());
}
else
{
MessageBox.Show("Data not found");
}
dReader.Close();
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource = namesCollection;
}
现在如何自动填充 textbox2 和 textbox3?
问候。