sendkeys.send(" {RIGHT}")在datagridviewcell中

时间:2015-07-18 22:48:12

标签: vb.net datagridview mouseevent sendkeys

我的程序在到达sendkeys.send("{RIGHT}")

时崩溃了

以下代码

Private Sub dataGridViewDim_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles DataGridViewDim.MouseUp

        If e.Button = MouseButtons.Left Then
            Dim hit As DataGridView.HitTestInfo = _
                DataGridViewDim.HitTest(e.X, e.Y)
            If hit.Type = DataGridViewHitTestType.Cell Then
                DataGridViewDim.BeginEdit(True)
                SendKeys.Send("{RIGHT}") ' crashes when it gets here
            Else
                DataGridViewDim.EndEdit()
            End If
        End If
    End Sub

如果没有它适用于单击编辑模式。我想把cursosr一直设置到右边。

1 个答案:

答案 0 :(得分:0)

作为参考,这就是诀窍:

If e.Button = MouseButtons.Left Then
    Dim hit As DataGridView.HitTestInfo = _
        DataGridViewDim.HitTest(e.X, e.Y)
    If hit.Type = DataGridViewHitTestType.Cell Then
        DataGridViewDim.BeginEdit(True)
        Dim lengstr As Integer = DataGridViewDim.CurrentCell.Value.ToString.Length
        Dim EditBox = DirectCast(DataGridViewDim.EditingControl, TextBox)
        If IsNothing(EditBox) = False Then EditBox.SelectionStart = lengstr
    Else
        DataGridViewDim.EndEdit()
    End If
End If