Click here to Skip to main content
14,429,343 members
Rate this:
Please Sign up or sign in to vote.
See more:
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();
            }
        }
Posted
Updated 13-Nov-14 0:37am
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

   
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.
Vivek.anand34 14-Nov-14 3:31am
   
this my code:
private void emp()
{
using (SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
sqlconn.Open();
SqlCommand cmd = new SqlCommand("select EmpName from EmpDetails where EmpName like '" + ACName.Text + "%' ", sqlconn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> EmpNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
EmpNames.Add(dt.Rows[i]["EmpName"].ToString());
}
ACName.DataContext = EmpNames;
FirstName = EmpNames.ToString();
}
}
rahulkichur 14-Nov-14 3:35am
   
What is the output?
Vivek.anand34 14-Nov-14 5:23am
   
didn't display anything..
rahulkichur 14-Nov-14 5:34am
   
Whether the database action returns rows?
rahulkichur 14-Nov-14 5:35am
   
I cant see your design page whether you have changed the design to suite data context
Vivek.anand34 14-Nov-14 6:13am
   
this is a design code:
<toolkit:autocompletebox x:name="ACName"
minimumprefixlength="1" itemssource="{Binding}" filtermode="Contains" valuememberpath="FirstName" istextcompletionenabled="True">

Vivek.anand34 14-Nov-14 6:14am
   
design codes didn't display in this comment box.
rahulkichur 16-Nov-14 22:25pm
   
It might be the issue with your design page where binding is done

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100