使用c#代码在wpf中自动完成文本框
问题描述:
亲爱的朋友们,
我在wpftoolkit中尝试过autocompletebox:我试过这个代码不起作用:
Dear Friends,
I have tried autocompletebox in wpftoolkit: I tried this code its not worked:
private void PopulateNames(object sender, PopulatingEventArgs e)
{
try
{
conn.Open();
List<string> types = new List<string>();
string accountQuery = "SELECT EmpName FROM EmpDetails WHERE EmpName LIKE '" + e.Parameter + "%'";
SqlDataReader accountTypes = null;
SqlCommand query = new SqlCommand(accountQuery, conn);
accountTypes = query.ExecuteReader();
while (accountTypes.Read())
{
types.Add(accountTypes["EmpName"].ToString());
}
AutoCompleteBox accountType = (AutoCompleteBox)sender;
accountType.ItemsSource = types;
accountTypes.Close();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
// Close the DB if there was an error.
if (conn.State == ConnectionState.Open)
conn.Close();
}
}
答
请参阅 http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html#.VGWGdvmUf9s
它可能对你有帮助。
Please Refer "http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html#.VGWGdvmUf9s"
It may help you.