本文共 861 字,大约阅读时间需要 2 分钟。
重写: override bool ProcessCmdKey这个方法。每一次按键都会进入这个方法里
写了部分注释,其它的你们根据自己需要改一下就行 /// /// 控制datagirdview格跳转转换enter或tab /// /// /// /// protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { //加这个判断以免在列上按按钮会报错 if (keyData == Keys.Enter && this.dataGridView1.CurrentCell != null) { //return true; //这个return用来跳过默认的Enter事件效果 //return base.ProcessCmdKey(ref msg, Keys.Tab); int columnC = dataGridView1.CurrentCell.ColumnIndex; if(columnC==6) { //如果是最后一行就不进行操作 if (dataGridView1.CurrentCell.RowIndex + 1 == dataGridView1.Rows.Count) { return true; } //设置相应列,相当于按回车选中同一行的下一个单元格,效果同tab键 dataGridView1.CurrentCell=dataGridView1[2,(dataGridView1.CurrentCell.RowIndex+1)]; } //其它列正常操作 if (columnC == 7) { return base.ProcessCmdKey(ref msg, keyData); } else { SendKeys.Send("{Tab}"); return true; } } //return false; return base.ProcessCmdKey(ref msg, keyData); }转载地址:http://qgtiz.baihongyu.com/