if Cint(datagrid.text)>0 and Cint(datagrid.text)<100 then row=row+1
Dim strOld As StringPrivate Sub DataGrid1_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer) strOld = OldValue End SubPrivate Sub DataGrid1_BeforeUpdate(Cancel As Integer) If DataGrid1.Text < 0 Or DataGrid1.Text > 10 Then MsgBox "数据非法~" DataGrid1.Text = strOld 'Cancel = True End If End Sub
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then DataGrid1.Row = DataGrid1.Row + 1 End Sub
dim gtext as string gtext=..........'这行中的某数据 if Cint(gtext)>0 and Cint(gtext)<100 then datagrid.row=datagrid.row+1 else msgbox"您刚才输入的数据有误,请重新输入!",,"提示" end if
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If Cint(datagrid1.text)>0 and Cint(datagrid2.text)<100 and keycode=vbKeyReturn Then DataGrid1.Row = DataGrid1.Row + 1 DataGrid1.Col = DataGrid1.Col End If End Sub
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then If DataGrid1.Text < 0 Or DataGrid1.Text > 100 Then MsgBox "数据输入有误!" Exit Sub End If DataGrid1.Row = DataGrid1.Row + 1 End If End Sub
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then If DataGrid1.Text < 0 Or DataGrid1.Text > 100 Then MsgBox "数据输入有误!" Exit Sub End If DataGrid1.Row = DataGrid1.Row + 1 DataGrid1.Col = 0 End If End Sub
谢谢各位,如下写可以解决我的问题。但是仍有两个BUG 1。输入错误信息时,如果用鼠标选择时,判断不起作用。如果用事件BeforeColUpdate可以对任何的变换单元格进行判断,但是用回车时,第一次焦点停留在原地,再按一次报DataGrid1.Row = DataGrid1.Row + 1出错 实时错误‘7011’ 2。用KeyDown事件需按两次回车,不知是什么原因Private Sub datagrid1_KeyPress(Keycode As Integer) If Keycode = 13 Then If CInt(DataGrid1.Text) < 0 Or CInt(DataGrid1.Text) > 100 Then MsgBox "数据输入出错¡" Exit Sub End If DataGrid1.Row = DataGrid1.Row + 1
strOld = OldValue
End SubPrivate Sub DataGrid1_BeforeUpdate(Cancel As Integer)
If DataGrid1.Text < 0 Or DataGrid1.Text > 10 Then
MsgBox "数据非法~"
DataGrid1.Text = strOld
'Cancel = True
End If
End Sub
If KeyCode = 13 Then DataGrid1.Row = DataGrid1.Row + 1
End Sub
gtext=..........'这行中的某数据
if Cint(gtext)>0 and Cint(gtext)<100 then
datagrid.row=datagrid.row+1
else
msgbox"您刚才输入的数据有误,请重新输入!",,"提示"
end if
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If Cint(datagrid1.text)>0 and Cint(datagrid2.text)<100 and keycode=vbKeyReturn Then
DataGrid1.Row = DataGrid1.Row + 1
DataGrid1.Col = DataGrid1.Col
End If
End Sub
Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
If DataGrid1.Text < 0 Or DataGrid1.Text > 100 Then
MsgBox "数据输入有误!"
Exit Sub
End If
DataGrid1.Row = DataGrid1.Row + 1
End If
End Sub
If KeyCode = 13 Then
If DataGrid1.Text < 0 Or DataGrid1.Text > 100 Then
MsgBox "数据输入有误!"
Exit Sub
End If
DataGrid1.Row = DataGrid1.Row + 1
DataGrid1.Col = 0
End If
End Sub
1。输入错误信息时,如果用鼠标选择时,判断不起作用。如果用事件BeforeColUpdate可以对任何的变换单元格进行判断,但是用回车时,第一次焦点停留在原地,再按一次报DataGrid1.Row = DataGrid1.Row + 1出错 实时错误‘7011’
2。用KeyDown事件需按两次回车,不知是什么原因Private Sub datagrid1_KeyPress(Keycode As Integer)
If Keycode = 13 Then
If CInt(DataGrid1.Text) < 0 Or CInt(DataGrid1.Text) > 100 Then
MsgBox "数据输入出错¡"
Exit Sub
End If
DataGrid1.Row = DataGrid1.Row + 1
End If
End Sub