Problem is the AutoComplete also shows up for columns other than column 1. It won't initially until I enter text in column 1 and then it will start showing for other columns.
My code :
public AutoCompleteStringCollection ClientListDropDown()
{
AutoCompleteStringCollection asc = new AutoCompleteStringCollection();
try
{
Query = "Select top 5 title from customer "; // just removed where name like '%" + txtDVNo.Text + "%' plz check
cmd = new SqlCommand(Query, GlobalVars.conn);
dr = cmd.ExecuteReader();
if ((dr != null) && (dr.HasRows))
while (dr.Read())
asc.Add(dr.GetValue(0).ToString());
dr.Close();
cmd.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return asc;
}
private void dgvDVDetails_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvDVDetails.CurrentCell.ColumnIndex == 1)
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
prodCode.AutoCompleteCustomSource = ClientListDropDown();
prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
}
Try This:
private void dgvDVDetails_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvDVDetails.CurrentCell.ColumnIndex == 1)
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
prodCode.AutoCompleteCustomSource = ClientListDropDown();
prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
else
{
TextBox prodCode = e.Control as TextBox;
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.None;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With