0

这是我按 Enter 键并移动到下一个单元格的代码:

Private Sub dvFromAlloc_CellEndEdit(ByVal sender As Object, ByVal e As   System.Windows.Forms.DataGridViewCellEventArgs) Handles dvFromAlloc.CellEndEdit
    SendKeys.Send("{up}")
    SendKeys.Send("{right}")
End Sub

Private Sub dvFromAlloc_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dvFromAlloc.KeyDown
    If e.KeyCode = Keys.Enter Then
        SendKeys.Send("{up}")
        SendKeys.Send("{right}")
    End If
End Sub

这是完美的工作,现在我想要的是如果用户在最后一列,我怎样才能将单元格移动到第二行的第一列?

谢谢你。

4

2 回答 2

1

你可以在你的活动中试试这个KeyDown..

Private Sub dvFromAlloc_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dvFromAlloc.KeyDown
    If e.KeyCode = Keys.Enter Then

        dvFromAlloc.CurrentCell = dvFromAlloc.Rows(dvFromAlloc.CurrentCell.RowIndex + 1).Cells(0)
        dtg.Rows(i).Cells(aColumn(x))
    End If
End Sub
于 2013-09-05T06:48:40.077 回答
0

在 Win 表单中处理 Datagridview 的 Enter 键。

bool notlastColumn = true;

    protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
    {
        int icolumn = dataGridView1.CurrentCell.ColumnIndex;
        int irow = dataGridView1.CurrentCell.RowIndex;
        int i = irow;
        if (keyData == Keys.Enter)
        {
            if (icolumn == dataGridView1.Columns.Count - 1)
            {

                //dataGridView1.Rows.Add();
                if (notlastColumn == true  )
                {
                   dataGridView1.CurrentCell= dataGridView1.Rows[i].Cells[0];
                }
                dataGridView1.CurrentCell = dataGridView1[0, irow + 1];

            }
            else
            {
                dataGridView1.CurrentCell = dataGridView1[icolumn + 1, irow];
            }
            return true;
        }
        else
            return base.ProcessCmdKey(ref msg, keyData);
    }
于 2014-01-16T07:20:18.570 回答