Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:47:59+00:00 2026-06-16T01:47:59+00:00

I tried to make an auto-complete TextBox like Google Search with C# in a

  • 0

I tried to make an auto-complete TextBox like Google Search with C# in a WPF application, basically what I want to do is have an auto-complete TextBox which is bound to a SQL database table. the table has 2 fields(Barcode and Name),my code as below:

In XAML :

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="37*" />
        <RowDefinition Height="88*" />
    </Grid.RowDefinitions>
    <TextBlock Text="Type Your Search :" HorizontalAlignment="Left"            VerticalAlignment="Bottom" Width="112" Height="15.96" Margin="31,0,0,4" />

    <TextBox HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="25" Width="325" Margin="0,0,10,0" x:Name="txtCAuto" TextWrapping="NoWrap" />

    <ListBox x:Name="lbSuggestion" SelectionChanged="lbSuggestion_SelectionChanged" Background="LightYellow" Grid.Row="1" Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Top" Width="325" Margin="0,0,10,0"/>
</Grid>

Code behind:

    List<string> nameList;
    List<Product> prodList;

    public List<string> SelProd4Sale(string str )
    {
        string constr = "Data Source=.;Initial Catalog=AgamistaStore;User ID=emad2012;Password=emad_2012";
        SqlConnection SqlCon = new SqlConnection(constr);
        SqlCommand SqlCmdProds = new SqlCommand();
        SqlCmdProds.Connection = SqlCon;
        SqlCmdProds.CommandType = CommandType.Text;
        SqlCmdProds.CommandText = "SELECT dbo.ProductsTbl.ProductID,ProductsTbl.ProductBarcode," + 
            "dbo.ProductsTbl.ProductName, dbo.ProductsTbl.SalePrice FROM dbo.ProductsTbl ";
        SqlCon.Open();
        SqlDataAdapter dapProds = new SqlDataAdapter();
        dapProds.SelectCommand = SqlCmdProds;
        DataSet dsProds = new DataSet();
        dapProds.Fill(dsProds);
        SqlCon.Close();
        prodList = new List<Product>();
        for (int i = 0; i < dsProds.Tables[0].Rows.Count; i++)
        {
            prodList.Add(new Product
                            (dsProds.Tables[0].Rows[i]["ProductBarcode"].ToString(),
                            dsProds.Tables[0].Rows[i]["ProductName"].ToString());
        }
        dsProds = null;

        nameList = new List<string>() 
        {
           prodList.ToString()
        };

        return nameList;
    }

    public Window2()
    {
        InitializeComponent();
        SelProd4Sale(txtCAuto.Text);
        txtCAuto.TextChanged += new TextChangedEventHandler(txtAuto_TextChanged);
    }

    #region TextBox-TextChanged-txtAuto
    private void txtAuto_TextChanged(object sender, TextChangedEventArgs e)
    {
        string typedString = txtCAuto.Text.ToUpper();
        List<string> autoList = new List<string>();
        autoList.Clear();

        foreach (string item in nameList)
        {
            if (!string.IsNullOrEmpty(txtCAuto.Text))
            {
                if (item.StartsWith(typedString))
                {
                    autoList.Add(item);
                }
            }
        }

        if (autoList.Count > 0)
        {
            lbSuggestion.ItemsSource = autoList;
            lbSuggestion.Visibility = Visibility.Visible;
        }
        else if (txtCAuto.Text.Equals(""))
        {
            lbSuggestion.Visibility = Visibility.Collapsed;
            lbSuggestion.ItemsSource = null;
        }
        else
        {
            lbSuggestion.Visibility = Visibility.Collapsed;
            lbSuggestion.ItemsSource = null;
        }
    }
    #endregion

    #region ListBox-SelectionChanged-lbSuggestion
    private void lbSuggestion_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (lbSuggestion.ItemsSource != null)
        {
            lbSuggestion.Visibility = Visibility.Collapsed;
            txtCAuto.TextChanged -= new TextChangedEventHandler(txtAuto_TextChanged);
            if (lbSuggestion.SelectedIndex != -1)
            {
                txtCAuto.Text = lbSuggestion.SelectedItem.ToString();
            }
            txtCAuto.TextChanged += new TextChangedEventHandler(txtAuto_TextChanged);
        }
    }
    #endregion
}

class Product
{
    private string _ProductBarcode = "";
    private string _ProductName = "";

    public Product(string prodName,string prodBarcode)
    {
        this._ProductBarcode = prodBarcode;
        this._ProductName = prodName;
    }

    public string ProductBarcode
    {
        get { return _ProductBarcode; }
        set { _ProductBarcode = value; }
    }

    public string ProductName
    {
        get { return _ProductName; }
        set { _ProductName = value; }
    }

}

When I run this I got “System.Collections.Generic.List” as result instead of data.

Can somebody help me please & tell me what’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:48:00+00:00Added an answer on June 16, 2026 at 1:48 am

    The problem is in this code:

    nameList = new List<string>() 
            {
               prodList.ToString()
            };
    

    Since ToString() it is not overriden in List<T> it just returns a class name (basic implementation from System.Object). As result, your list contains single entry "System.Collection.Generic.List". To apply ToString() to elements of a list and create new list, replace that code with:

    nameList = productList.Select(p => p.ToString()).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to make a layout look like it It looks like kinda button
I tried to make my textbox type in currency format. I did it, but
I tried to make admin panel and I am using sessions , but have
I have an auto-complete input, works great .. When I fill the content through
I have a WPF application with the autocomplete box via the toolkit (VS 2008).
So, i have read at least 20-30 auto complete problems here on so and
I tried on linux and ash from busybox does auto-complete command line... But under
I'm trying to make an application compatible with the auto proxy API provided by
Q: I want to make autocomplete facility like the one exists in yahoo mail
I am making a auto suggestion / complete textbox in C#, i followed below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.