Reputation: 23
Here is the code I am using for search, it returns a value when we type a whole name, but I need a autocomplete textbox, that shows suggestions as I type a partial name.
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();
}
Upvotes: 1
Views: 9866
Reputation: 1620
you can also add the AutoCompleteBox
into the toolbox by clicking on it and then Choose Items, go to WPF Components, type in the filter AutoCompleteBox
, which is on the System.Windows
Upvotes: -1
Reputation: 12439
You can create an AutoCompleteTextBox
by using a simple textbox
control and a listbox
control. Here is a tutorial which will guide you through the whole process.
But if you don't want to create it yourself so you can just use an already created control by someone else. Download it from here.
And here is the tutorial teaching you how to use that control.
Upvotes: 3