使用c#代码在wpf中自动完成文本框 [英] Autocomplete textbox in wpf with c# code

查看:223
本文介绍了使用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.


这篇关于使用c#代码在wpf中自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆