VB程序员博客
vb5 + windows xp
使用了 msflexgrid 和 text,使得点击 msflexgrid 的任何一个单元格,按下鼠标后都能够编辑。
请问:如何限制 msflexgrid 的某列只能输入数字,且该数只能大于0小于150 ?
msflexgrid一般只用于显示数据,要通过编程才能使他可以编辑.
Option Explicit
Dim flag As Long
Dim r As Long
Dim c As Long
Private Sub Form_Load()
With grid1
.Rows = 20
.Cols = 16
End With
End Sub
Private Sub Form_Resize()
grid1.Move 1, 1, Me.ScaleWidth - 2, Me.ScaleHeight - 2
End Sub
Private Sub grid1_EnterCell()
If flag = 1 Then
With grid1
.Row = r
.Col = c
.SetFocus
End With
End If
End Sub
Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim X As Long
Dim Y As Long
Dim L As Long
Dim Tmp As String
X = grid1.Col
Y = grid1.Row
Select Case KeyCode
Case 13
X = X + 1
If X >= grid1.Cols Then
X = 1
Y = Y + 1
If Y >= grid1.Rows Then grid1.Rows = grid1.Rows + 1
End If
grid1.Col = X
grid1.Row = Y
Case 8
Tmp = grid1.Text
L = Len(Tmp) - 1
If L > -1 Then grid1.Text = Left(Tmp, L)
Case Else
If KeyCode < 48 Or KeyCode > 57 Then
MsgBox "请输入数字!"
Else
grid1.Text = grid1.Text & Chr(KeyCode)
End If
End Select
End Sub
Private Sub grid1_LeaveCell()
flag = 0
With grid1
If .Text <> "" Then
If CLng(.Text) < 0 Or CLng(.Text) > 150 Then
MsgBox "数字只限0–150!"
r = grid1.Row
c = grid1.Col
flag = 1
End If
End If
End With
End Sub
顶楼上,我很懒,收藏下…
呵呵,望LZ有用的话放分就行
标签: , MSFLEXGRID, text, 限制