C# datagridview利用keyup事件,EditingControlShowing事件,来实时捕获正在编辑的单元格的内容
说明:
1、添加datagridview的EditingControlShowing事件,
2、在EditingControlShowing事件中在添加keyup事件
3、在keyup事件中捕获输入
注: datagridview在编辑时,被编辑的单元格相当于TextBox。
代码:
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
e.Control.KeyUp += new KeyEventHandler(keyup);
}
}
private void keyup(object sender, KeyEventArgs e)
{
//str即所要获取的内容
string str = (sender as TextBox).Text;
textBox2.Text = str;
}