Solarion
Honorary Master
- Joined
- Nov 14, 2012
- Messages
- 28,050
- Reaction score
- 17,804
I've put this handy function together however so far it only works with one Texbox control. I want to make it more dynamic to work across multiple Texboxes. I'm thinking of maybe passing in an array of controls or something, to make it work with both the music styles and last name Texboxes.
The main reason #2 is that I want to put this function into a class instead of in the main form code with is not cool.
Any suggestions are appreciated.

The main reason #2 is that I want to put this function into a class instead of in the main form code with is not cool.
Any suggestions are appreciated.

Code:
//"SELECT distinct FirstName FROM People"
private void Autocomplete(string Sql)
{
try
{
sqlConn.Open();
SqlCommand cmd = new SqlCommand(Sql, sqlConn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "People");
AutoCompleteStringCollection col = new AutoCompleteStringCollection();
int i = 0;
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
col.Add(ds.Tables[0].Rows[i]["FirstName"].ToString());
}
txtFirstName.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtFirstName.AutoCompleteCustomSource = col;
txtFirstName.AutoCompleteMode = AutoCompleteMode.Suggest;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}