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?)
Roei BarPosted Oct 8, 2009, 2:02 AM
this.customersTableAdapter.Fill(this.flowerShoppingDataSet.Customers);
make sure that your dataset has a fill method and it receives a Customers Object
i think by the error that its not.
just change it to
this.flowerShoppingDataSet.Customers = this.customersTableAdapter.Fill();
that should do the trick
Kirtan PatelPosted Oct 7, 2009, 9:44 PM
Here is Custom Code ( Tested And Working )
dont forget to mark "do you like answer" it will give me credits :)
private void Form1_Load(object sender, EventArgs e)
{
AutoCompleteStringCollection autolist = new AutoCompleteStringCollection();
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from users",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow r in dt.Rows)
{
autolist.Add(r[0].ToString());
}
textBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox1.AutoCompleteCustomSource = autolist;
}