日期:2014-05-18  浏览次数:20702 次

回车让一个DataGridView中指定的单元格光标跳到另一个单元格.
回车让一个DataGridView中指定的单元格光标跳到另一个单元格. 
如我在DataGridView(Winform)的单元格DataGridView1.Rows[0].Cells[0]中录入完数字后,回车..  
让光标跳到指定的单元格,如跳到DataGrid1.Rows[0].Cells[3]单元格.  
谢谢

------解决方案--------------------
将Winfrom1的KeyPreview置为true,dataGridView的SelectionMode置为CellSelect然后重写事件
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
if (keyData == Keys.Enter)

if (dataGridView1.CurrentRow.Cells[0].Selected)
{
dataGridView1.CurrentRow.Cells[3].Selected = true;
//todo
}
return true;
}
 }
应该可以这样实现
------解决方案--------------------
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar == 13)
{
dataGridView1.CurrentCell = this.dataGridView1[this.dataGridView1.CurrentCell.ColumnIndex , this.dataGridView1.CurrentRow.Index+ 1]; }
}
//是个例子,你再加点判断就行了