Welcome

Welcome Anonymous

Friday, April 30, 2010

Auto Complete Feature for any control

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;

No comments:

Post a Comment