各位大神:
我在datagridview编辑时,使用editingcontrolshowing事件抓取向下键时,代码被执行了多次(窗口弹出了好几次)。不知道为什么,请大家帮我看看。谢谢啦。代码如下:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex==2 && dataGridView1.CurrentRow.Index==dataGridView1.Rows.Count-1)
{
DataGridViewTextBoxEditingControl dgvtxt = e.Control as DataGridViewTextBoxEditingControl;
dgvtxt.PreviewKeyDown += new PreviewKeyDownEventHandler(dgvtxt_PreviewKeyDown);
}
}
void dgvtxt_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
MessageBox.Show("有反应了!");
}
}
请大家帮我看看。谢谢!