SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=tts;Integrated Security=True");
//creat auto complete Collection
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
//get the data from database
SqlDataAdapter da1 = new SqlDataAdapter("select name from contacts ", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
//add the student name into auto complete collection
collection.Add(dt1.Rows[i].ItemArray[0].ToString());
}
}
//after adding the student names into auto complete collection bind the collection to Combobox
toolStripComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
toolStripComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
toolStripComboBox1.AutoCompleteCustomSource = collection;
//creat auto complete Collection
AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
//get the data from database
SqlDataAdapter da1 = new SqlDataAdapter("select name from contacts ", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
//add the student name into auto complete collection
collection.Add(dt1.Rows[i].ItemArray[0].ToString());
}
}
//after adding the student names into auto complete collection bind the collection to Combobox
toolStripComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
toolStripComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
toolStripComboBox1.AutoCompleteCustomSource = collection;
Comments
Post a Comment