Ali Khavari

Ali Khavari

  • NA
  • 1
  • 0

Autocomplete textbox in C#

Oct 7 2009 7:16 PM

Hi Everybody,
I developed a Windows Form Application with C# for a Flower Shopping Store. I want, one of the Textboxes of the form be in Autocomplete mode and fetch it's data from a dataset that is in the form too. please help me. My Code is as Follow:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

 

namespace FlowerShopping

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

 

        private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)

        {

            this.Validate();

            this.customersBindingSource.EndEdit();

            this.tableAdapterManager.UpdateAll(this.flowerShoppingDataSet);

 

        }

 

        private void Form1_Load(object sender, EventArgs e)

        {

            // TODO: This line of code loads data into the     'flowerShoppingDataSet.Customers' table. You can move, or remove it, as needed.

            this.customersTableAdapter.Fill(this.flowerShoppingDataSet.Customers);

            //creat auto complete Collection

            AutoCompleteStringCollection collection = new AutoCompleteStringCollection();

            //get the data from dataset.

            FlowersNameDataSet ad = new FlowersNameDataSet();

            DataTable dt = new DataTable();

            ad.Fill(dt);

            if (dt.Rows.Count > 0)

            {

                for (int i = 0; i < dt.Rows.Count; i++)

                {

                    //add the student name into auto complete collection

                    collection.Add(dt.Rows[i].ItemArray[0].ToString());

                }

            }

            //after adding the student names into auto complete collection bind the collection to textbox

            flower_NameTextBox.AutoCompleteMode = AutoCompleteMode.Suggest;

            flower_NameTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource;

            flower_NameTextBox.AutoCompleteCustomSource = collection;

 

        }

    }

}

 

       

 

 

 

Error      1              'FlowerShopping.FlowersNameDataSet' does not contain a definition for 'Fill' and no extension method 'Fill' accepting a first argument of type 'FlowerShopping.FlowersNameDataSet' could be found (are you missing a using directive or an assembly reference?)       
 


Answers (2)