Autocomplete for column not working
I use following code for autocomplete first column but its not working plz help?
private void dgvInovce_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (this.dgvInovce.CurrentCell.ColumnIndex == 0)
{
TextBox tb = e.Control as TextBox;
if (tb != null)
{
AutoCompleteStringCollection str = new AutoCompleteStringCollection();
str.Add("A");
str.Add("B");
tb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
tb.AutoCompleteCustomSource = str;
tb.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
txtDgvQuntity = e.Control as TextBox;
txtDgvSaleRate = e.Control as TextBox;
txtDgvDiscount = e.Control as TextBox;
txtDgvQuntity.KeyPress -= new KeyPressEventHandler(txtDgvQuntity_KeyDown);
txtDgvSaleRate.KeyPress -= new KeyPressEventHandler(txtDgvSaleRate_KeyDown);
txtDgvDiscount.KeyPress -= new KeyPressEventHandler(txtDgvDiscount_KeyDown);
if (this.dgvInovce.CurrentCell.ColumnIndex == 1)
{
txtDgvQuntity.KeyPress += new KeyPressEventHandler(txtDgvQuntity_KeyDown);
}
if (this.dgvInovce.CurrentCell.ColumnIndex == 3)
{
txtDgvSaleRate = e.Control as TextBox;
if (txtDgvSaleRate.Text.Trim().Length > 0)
txtDgvSaleRate.Clear();
txtDgvSaleRate.KeyPress += new KeyPressEventHandler(txtDgvSaleRate_KeyDown);
}
if (this.dgvInovce.CurrentCell.ColumnIndex == 4)
{
txtDgvDiscount = e.Control as TextBox;
txtDgvDiscount.KeyPress += new KeyPressEventHandler(txtDgvDiscount_KeyDown);
}
}
}