在MSFLEXGRID控件中每一個CELL格的內容是不可以由用戶直接編輯的但是我們可以通過一些小技巧來方便的實現這編輯功能來擴展MSFLEXGRID的應用(在實際應用中這是很常用的功能)。
你只需按下面的做即可輕松實現編輯MSFLEXGRID控件數據的功能
例在窗體上放一文本框text1,和一MSFLEXGRID控件flexgrid1
加入下例代碼
Private Sub Form_Load() Text1.Move -10000, -10000, 1, 1 End Sub Private Sub MSFlexGrid1_EnterCell() MSFlexGrid1.CellBackColor = vbBlue MSFlexGrid1.CellForeColor = vbWhite Text1.Text = MSFlexGrid1.Text Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text) End Sub Private Sub MSFlexGrid1_LeaveCell() MSFlexGrid1.CellBackColor = vbWhite MSFlexGrid1.CellForeColor = vbBlue End Sub Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Text1.SetFocus End Sub Private Sub Text1_Change() MSFlexGrid1.Text = Text1.Text End Sub Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown KeyCode = 0 End Select End Sub
ok,這樣一個可編輯的MSFLEXGRID控件就完成了,簡單吧!!