TextBox TextChanged Event on DataGridView Cell

private void dgvPurItem_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
 int colIndex;
 int rowIndex;
 var txtBox = e.Control as TextBox;
 colIndex = dgvPurItem.CurrentCell.ColumnIndex;
 rowIndex = dgvPurItem.CurrentCell.RowIndex;
 if (e.Control is TextBox)
  if (txtBox != null)

   txtBox.CharacterCasing = CharacterCasing.Upper;
   txtBox.TextChanged += new EventHandler(ItemTxtBox_TextChanged);
   txtBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
   txtBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
   txtBox.AutoCompleteCustomSource.Add("Item 1");
   txtBox.AutoCompleteCustomSource.Add("Item 2");
   txtBox.AutoCompleteCustomSource.Add("Item 3");

void ItemTxtBox_TextChanged(object sender, EventArgs e)
    if ((sender as TextBox).Text != null && (sender as TextBox).Text.Trim() != "")
       MessageBox.Show((sender as TextBox).Text);

4 thoughts on “TextBox TextChanged Event on DataGridView Cell

  1. greate solution and it works fine.

    I just wonder why that event does not exist by default, although the visual studion or vb.net for datagridview add the textbox as System.Windows.Forms.DataGridViewTextBoxColumn() but does not recognize it as Textbox and had to be casted to trextbox…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s