在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控件就完成了,简单吧!!
http://ngsoft.shangdu.net
本文地址:http://com.8s8s.com/it/it6894.htm