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)
                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())
                AutoCompleteBox accountType = (AutoCompleteBox)sender;
                accountType.ItemsSource = types;
            catch (Exception ex)

                // Close the DB if there was an error.
                if (conn.State == ConnectionState.Open)
Updated 13-Nov-14 0:37am
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

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 ""

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))
SqlCommand cmd = new SqlCommand("select EmpName from EmpDetails where EmpName like '" + ACName.Text + "%' ", sqlconn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
List<string> EmpNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
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