在MSFLEXGRID控件中每一个CELL格的内容是不可以由用户直接编辑的但是我们可以通过一些小技巧来方便的实现这编辑功能来扩展MSFLEXGRID的应用(在实际应用中这是很常用的功能)。
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)你只需按下面的做即可轻松实现编辑MSFLEXGRID控件数据的功能
例在窗体上放一文本框text1,和一MSFLEXGRID控件flexgrid1
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)加入下例代码
Private Sub Form_Load() Text1.Move -10000, -10000, 1, 1End SubPrivate Sub MSFlexGrid1_EnterCell() MSFlexGrid1.CellBackColor = vbBlue MSFlexGrid1.CellForeColor = vbWhite Text1.Text = MSFlexGrid1.Text Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text)End SubPrivate Sub MSFlexGrid1_LeaveCell() MSFlexGrid1.CellBackColor = vbWhite MSFlexGrid1.CellForeColor = vbBlueEnd SubPrivate Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Text1.SetFocusEnd SubPrivate Sub Text1_Change() MSFlexGrid1.Text = Text1.TextEnd SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown KeyCode = 0 End SelectEnd Sub
ok,这样一个可编辑的MSFLEXGRID控件就完成了,简单吧!!