为MSHFlexGrid添加表格编辑功能
2009-05-15 12:12
309 查看
虽然MSHFlexGrid的功能比较强大,样式比较丰富,可惜它不支持数据编辑。我以前俺用TextBox实现了它的编辑功能,总算弥补了MSHFlexGrid的不足。
首先,新建一个标准EXE工程,然后, 在工程部件里选择“Microsoft Hierarchical Flex Grid Control 6.0 (OLEDB)”,在Form里添加一个MSHFlexGrid控件,命名为msGrid,再添加一个TextBox控件,命名为txtCell,最后在Form的代码窗口里粘贴以下代码,运行一下工程,一个支持数据编辑的表格就算大功告成了。
首先,新建一个标准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 = False End Sub Private Sub msGrid_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) If Button <> 1 Then Exit Sub msGrid.ColSel = msGrid.Col msGrid.RowSel = msGrid.Row msGrid.Redraw = True If msGrid.Row > msGrid.FixedRows - 1 And msGrid.Col > msGrid.FixedCols - 1 And msGrid.CellWidth > 0 And msGrid.CellHeight > 0 Then txtCell.Move msGrid.Left - 1 + msGrid.CellLeft / 15, msGrid.Top - 1 + msGrid.CellTop / 15, msGrid.CellWidth / 15, msGrid.CellHeight / 15 txtCell.Tag = "No" txtCell.Text = msGrid.Text txtCell.Tag = "" txtCell.SetFocus End If End Sub Private Sub msGrid_Scroll() txtCell.Move -100, -100 End Sub Private Sub txtCell_Change() If txtCell.Tag <> "No" And msGrid.Col >= msGrid.FixedCols And msGrid.Row >= msGrid.FixedRows Then msGrid.Text = txtCell.Text End If End Sub Private Sub txtCell_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case 37 If msGrid.Col > msGrid.FixedCols And txtCell.SelStart = 0 Then msGrid.Col = msGrid.Col - 1 KeyCode = 0 End If Case 38 If msGrid.Row > msGrid.FixedRows And txtCell.SelStart = 0 Then msGrid.Row = msGrid.Row - 1 KeyCode = 0 End If Case 39 If msGrid.Col < msGrid.Cols - 1 And txtCell.SelStart = Len(txtCell.Text) Then msGrid.Col = msGrid.Col + 1 KeyCode = 0 End If Case 40 If msGrid.Row < msGrid.Rows - 1 And txtCell.SelStart = Len(txtCell.Text) Then msGrid.Row = msGrid.Row + 1 KeyCode = 0 End If Case 13 If msGrid.Col < msGrid.Cols - 1 Then msGrid.Col = msGrid.Col + 1 Else If msGrid.Row < msGrid.Rows - 1 Then msGrid.Row = msGrid.Row + 1 msGrid.Col = msGrid.FixedCols End If KeyCode = 0 Case 33 msGrid.SetFocus SendKeys Chr(33) Case 34 msGrid.SetFocus SendKeys Chr(34) End Select If KeyCode = 0 And msGrid.CellWidth > 0 And msGrid.CellHeight > 0 Then txtCell.Text = msGrid.Text txtCell.Move msGrid.Left - 1 + msGrid.CellLeft / 15, msGrid.Top - 1 + msGrid.CellTop / 15, msGrid.CellWidth / 15, msGrid.CellHeight / 15 txtCell.SelStart = 0 txtCell.SelLength = Len(txtCell.Text) End If End Sub
相关文章推荐
- 为MSHFlexGrid添加表格编辑功能
- js做带编辑,保存,删除,添加功能的表格
- bootstrap-table 插件二次开发添加表格行新增和编辑功能
- Swift - 给表格添加编辑功能(删除,插入)
- swift - 表格的编辑功能(添加、删除)
- UITableViewController 编辑功能中的,添加,删除,修改
- Jquery实现简单的表格添加、编辑、删除教程
- 编辑 Ext 表格(一)——— 动态添加删除行列
- JS实现动态表格的添加,修改,删除功能(推荐)
- jquery-easyui 中表格的行编辑功能
- JavaScript动态实现表格添加、删除、插入、上移、下移一行功能
- 黄聪:C#编写的Word操作类,有换页,添加表格,文本功能
- jquery-easyui中表格的行编辑功能
- jQuery仿Excel表格编辑功能的实现代码
- UITableViewController 编辑功能中的,添加,删除,修改
- 可编辑的table. 添加数据,修改数据。稍加修改就可以部署到ajax 动态表格中
- 四.用户管理页面(显示所有的用户信息,同时为用户的添加,编辑,修改密码,删除,修改权限等功能提供相应的链接) UserMange.aspx
- FckEditor添加右键菜单;增加编辑区右键图片删除功能(asp.net )(一)
- jQuery 实现双击编辑表格功能
- 在ASP.NET中应用Excel:(8)为HTML表格增加编辑功能