There are many events to handle or methods to override when something is changing or changed in DataGridView, and the right answer really depens on the your actual requirements.
- Do you want to customize the Enter key? Then you may want to override ProcessDialogKey.
- Do you want to customize the arrow keys? Then you may want to override ProcessDataGridViewKey
- Do you want to handle TextChanged event of the text box editing control? Then continue reading the answer!
- Do you want ...? Then let me know what exactly is your requirement and I'll share some idea.
Speaking of TextChanged
event of TextBox
, I guess you are interested in handling same exact event of the DataGridView while editing a text in text box of a cell. There's an event EditingControlShowing, that raises right before editing the cell when the editing control is gonna display. You can get the editing control and check if it's a TextBox
(it's actually a DataGridViewTextBoxEditingControl
which is derived from TextBox
), then just handle its TextChanged
event. For example:
private dgv1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
var txt = e.Control as TextBox;
if(txt!=null)
{
txt.TextChanged -= txt_TextChanged;
txt.TextChanged += txt_TextChanged;
}
}
private txt_TextChanged(object sender, EventArgs e)
{
//Do whatever you want.
}