[英]How to make autocomplete in wpf textbox?
這是我用於搜索的代碼,當我們鍵入一個全名時,它將返回一個值,但是我需要一個自動完成的文本框,該文本框會在我輸入部分名稱時顯示建議。
private void textBox3_KeyUp_1(object sender, System.Windows.Input.KeyEventArgs e)//Name Search
{
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select [Patient ID],[Patient Name],[Gender],[StudyDateTim],[Modality],[Study Name] From RepView Where [Patient Name] like '%" + textBox3.Text + "%'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGrid1.ItemsSource = dt.DefaultView;
con.Close();
}
您還可以通過單擊AutoCompleteBox
並將其添加到工具箱中,然后選擇“選擇項目”,轉到“ WPF組件”,鍵入在System.Windows
上的篩選器AutoCompleteBox
,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.