The contents of each cell in the MSFlexGrid control can not be edited directly by the user, but we can use some small techniques to facilitate the implementation of this editing function to extend the MSFlexGrid application (this is a very common function in practical applications).
You can easily edit the MSFlexGrid control data by just doing the following
Example puts a text box Text1 on a form, and a MSFlexGrid control FLEXGRID1
Add the following example code
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, such an editable MSFlexGrid control is complete, simple!!