Option ExplicitPrivate Sub Form_Load() Text1.BorderStyle = 0 Text1.Visible = False End SubPrivate Sub MSFlexGrid1_Click() With MSFlexGrid1 If .Col <> 2 Then Exit Sub '只能编辑第二列 Text1.Visible = True Text1.Move .CellLeft + .Left, .CellTop + .Top, .CellWidth, .CellHeight Text1.Text = .Text Text1.SetFocus End With End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 13 Then MSFlexGrid1.Text = Text1.Text Text1.Visible = False MSFlexGrid1.SetFocus End If End Sub
Text1.BorderStyle = 0
Text1.Visible = False
End SubPrivate Sub MSFlexGrid1_Click()
With MSFlexGrid1
If .Col <> 2 Then Exit Sub '只能编辑第二列
Text1.Visible = True
Text1.Move .CellLeft + .Left, .CellTop + .Top, .CellWidth, .CellHeight
Text1.Text = .Text
Text1.SetFocus
End With
End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
MSFlexGrid1.SetFocus
End If
End Sub
If col= 0 Then Cancel = True '将第一列设为不可编辑
End Sub