虽然MSHFlexGrid的功能比较强大,样式比较丰富,可惜它不支持数据编辑。我以前俺用TextBox实现了它的编辑功能,总算弥补了MSHFlexGrid的不足。
首先,新建一个标准EXE工程,然后, 在工程部件里选择“Microsoft Hierarchical Flex Grid Control 6.0 (OLEDB)”,在Form里添加一个MSHFlexGrid控件,命名为msGrid,再添加一个TextBox控件,命名为txtCell,最后在Form的代码窗口里粘贴以下代码,运行一下工程,一个支持数据编辑的表格就算大功告成了
代码如下:
Option Explicit
Private Sub Form_Load()
Dim i As Long
Me.ScaleMode = vbPixels
msGrid.Rows = 10
msGrid.Cols = 10
For i = 1 To 9
msGrid.TextMatrix(i, 0) = i
msGrid.TextMatrix(0, i) = Chr(i + 64)
Next
msGrid.HighLight = flexHighlightNever
msGrid.AllowBigSelection = False
msGrid.SelectionMode = flexSelectionFree
msGrid.FocusRect = flexFocusNone
txtCell.Move -100, -100
txtCell.BorderStyle = 0
End Sub
Private Sub msGrid_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> 1 Then Exit Sub
msGrid.Redraw = Fa