If .ColSel = .Col And .RowSel = .Row Then '表示没有多个栏位的选取,这时才真正是可以输入 Call toEditGrid(.Col, .Row) End If End If End If End With End Sub Private Sub MSFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyReturn And Not Text1.Visible Then With MSFlexGrid1 Call toEditGrid(.Col, .Row) End With End If End Sub 'TextBox上的输入反映到MsFlexGrid上 Private Sub Text1_Change() MSFlexGrid1.Text = Text1.Text End Sub '按下Down/Up 时结束TextBox的Keyin Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = vbKeyUp Then Text1.Visible = False MSFlexGrid1.SetFocus SendKeys "{up}" Else If KeyCode = vbKeyDown Then Text1.Visible = False MSFlexGrid1.SetFocus SendKeys "{down}" End If End If End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then KeyAscii = 0 Text1.Visible = False MSFlexGrid1.SetFocus End If If KeyAscii = vbKeyEscape Then KeyAscii = 0 MSFlexGrid1.Text = OldText Text1.Visible = False MSFlexGrid1.SetFocus End If End Sub
Private Sub Text1_LostFocus() Text1.Visible = False End Sub '设定TextBox於MSFlexGrid1的Current Cell上 Private Sub toEditGrid(ByVal C As Integer, ByVal R As Integer) With MSFlexGrid1 .Col = C: .Row = R Text1.Left = .Left + .ColPos(C) Text1.Top = .Top + .RowPos(R) If .Appearance = flex3D Then Text1.Left = Text1.Left + 2 * Screen.TwipsPerPixelX Text1.Top = Text1.Top + 2 * Screen.TwipsPerPixelY End If Text1.Width = .ColWidth(C) Text1.Height = .RowHeight(R) Text1.Text = .Text OldText = .Text End With Text1.Visible = True Text1.SelStart = Len(Text1.Text) Text1.SetFocus End Sub '以下程式处理Multi-column Selection的问题 Private Sub ProcMultiColSel(ByVal Shift As Integer) Dim i As Long, HaveSel As Boolean Dim SelSt As Long, SelEnd As Long Dim OldRowSel As Long, OldColSel As Long With MSFlexGrid1 OldRowSel = .RowSel: OldColSel = .ColSe