Private Sub DBGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then DBGrid1.Col = DBGrid1.Col + 1 End If End Sub
或者 Private Sub DBGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then DBGrid1.Row = DBGrid1.Row + 1 End If End Sub
在keypress事件中 If KeyAscii = vbKeyReturn Then With grid If .Row < .Rows - 1 Then .SetFocus SendKeys "{down}" ElseIf .Col < .Cols - 1 Then .SetFocus DoEvents nCol = .Col nRow = .Row .Row = 1 SendKeys "{right}" End If KeyAscii = 0 End With End If 这是行的,相反可以找到列的转化
Private Sub DataGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then SendKeys "{TAB}" End If End Sub
这样也可以 Private Sub DBGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyReturn Then If DBGrid1.Col = DBGrid1.Columns.Count - 1 Then DBGrid1.Col = 0 Else DBGrid1.Col = DBGrid1.Col + 1 End If End If End Sub
if keycode=vbenter then 移动焦点
If KeyAscii = 13 Then
DBGrid1.Col = DBGrid1.Col + 1
End If
End Sub
Private Sub DBGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
DBGrid1.Row = DBGrid1.Row + 1
End If
End Sub
If KeyAscii = vbKeyReturn Then
With grid
If .Row < .Rows - 1 Then
.SetFocus
SendKeys "{down}"
ElseIf .Col < .Cols - 1 Then
.SetFocus
DoEvents
nCol = .Col
nRow = .Row
.Row = 1
SendKeys "{right}"
End If
KeyAscii = 0
End With
End If
这是行的,相反可以找到列的转化
If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
End Sub
Private Sub DBGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
If DBGrid1.Col = DBGrid1.Columns.Count - 1 Then
DBGrid1.Col = 0
Else
DBGrid1.Col = DBGrid1.Col + 1
End If
End If
End Sub