问题描述
- datagridview编辑时获取向下键时的问题
-
各位大神:
我在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("有反应了!"); } }
请大家帮我看看。谢谢!
解决方案
dgvtxt.PreviewKeyDown += new PreviewKeyDownEventHandler(dgvtxt_PreviewKeyDown);
这个只要执行一次,最好放在构造函数,你每次都挂钩,自然就执行多次了。
解决方案二:
解决editorgridpanel编辑时视图向右移动的问题
DataGridView 绑定List 时 排序问题的解决
时间: 2024-08-04 13:41:26