Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If DataGrid1.Col <> 2 Then Exit Sub '限制第3列的数据为(-,X,*)
If KeyAscii = 8 Then Exit Sub
If Len(DataGrid1.Text) > 0 And DataGrid1.SelLength = 0 Then '限制只能输入一个字符
KeyAscii = 0
Exit Sub
End If
If KeyAscii <> Asc("-") And KeyAscii <> Asc("X") And KeyAscii <> Asc("*") Then
KeyAscii = 0
End If
End Sub
参考:
Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
If DataGrid1.Col <> 2 Then Exit Sub '限制第3列的数据为(-,X,*)
If KeyAscii = 8 Then Exit Sub
If KeyAscii <> Asc("-") And KeyAscii <> Asc("X") And KeyAscii <> Asc("*") Then
KeyAscii = 0
End If
End Sub