Here is the code I use. This works for me.
You can do more than one column by just adding more
If
-statements. I have several in my DGV that change depending on the previous ones so it is pretty flexible.
private void dgvCheckEntry_EditingControlShowing(Object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvCheckEntry.CurrentCell.ColumnIndex == 1)
{
SqlDataReader dreader;
SqlConnection conn = new SqlConnection(conStrn2);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
AutoCompleteStringCollection acBusIDSorce = new AutoCompleteStringCollection();
cmd.CommandText = "Select BusinessID from tblBusinessID";
conn.Open();
dreader = cmd.ExecuteReader();
if (dreader.HasRows == true)
{
while (dreader.Read())
acBusIDSorce.Add(dreader["BusinessID"].ToString());
}
else
{
MessageBox.Show("Data not Found");
}
dreader.Close();
TextBox txtBusID = e.Control as TextBox;
if (txtBusID != null)
{
txtBusID.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtBusID.AutoCompleteCustomSource = acBusIDSorce;
txtBusID.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
}