Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,
I have tried autocompletebox in wpftoolkit: I tried this code its not worked:

C#
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();
            }
        }
Posted
Updated 12-Nov-14 23:37pm
v2
Comments
Richard MacCutchan 13-Nov-14 4:27am    
What doesn't work?
Vivek.anand34 13-Nov-14 4:52am    
autocompletebox.. dropdown list in textbox

1 solution

 
Share this answer
 
Comments
Vivek.anand34 14-Nov-14 0:04am    
i need values comes from database but der not like that.. i not understood that code.
rahulkichur 14-Nov-14 0:24am    
please go through "http://www.codeproject.com/Tips/79158/AutoCompleteBox-Binding-Custom-Objects"

Here they followed two ways of binding the data one is using itemsource and the latter with datacontext.
lakshjoshi 14-Nov-14 1:39am    
call that in during page load check is it working..?
rahulkichur 14-Nov-14 3:04am    
yes it will
Vivek.anand34 14-Nov-14 3:30am    
sorry, its too not work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900