//捕捉按键

protected override bool ProcessCmdKey(ref Message msg,Keys keyData)

{

if (keyData == Keys.Right)
{
return this.ProcessRightKey(keyData);
}

private TextBox tbx = null;//定义一个texbox格式的变量,后面光标定位到具体位置要用其中自带的SelectionStart函数

//给定义textbox变量赋值、指向

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (tbx == null)
{
tbx = (TextBox)e.Control;//tbx赋值
}
}

//自定义的right按键功能,转到可编辑的下一列

public bool ProcessRightKey(Keys keyData)
{
bool isJump = true;
if (tbx != null)//tbx
{
isJump = (0 == tbx.SelectionLength) && (tbx.Text.Length == tbx.SelectionStart);
}

for (int i = dataGridView1.CurrentCell.ColumnIndex + 1; (isJump) && i < dataGridView1.ColumnCount; i++)
{
if (!dataGridView1.Columns[i].ReadOnly)
{
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[i];
break;
}
}

return isJump;
}

05-11 20:53