Private Sub Command3_Click() '填充网格 Dim R As Long Dim C As Long
For R = 0 To MSHFlexGrid1.Rows - 1 For C = 0 To MSHFlexGrid1.Cols - 1 MSHFlexGrid1.TextMatrix(R, C) = R & C Next Next End Sub
Private Sub Form_Load() With MSHFlexGrid1 Text1.Visible = False .RowHeight(-1) = 285 '设定网格是5000行.12列. .Rows = 5000: .Cols = 12 End With End Sub
'保存文件 Private Sub Command1_Click() Call SaveFile(MSHFlexGrid1, "c:\kk.grd") End Sub
'加载文件 Private Sub Command2_Click() Call LoadFile(MSHFlexGrid1, "c:\kk.grd") End Sub
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) Text1.Visible = False With MSHFlexGrid1 m_Row = .MouseRow m_Col = .MouseCol If m_Row < .FixedRows Then m_Row = .FixedRows If m_Col < .FixedCols Then m_Col = .FixedCols .Row = m_Row: .Col = m_Col Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight Text1.Text = .Text Text1.Visible = True Text1.SetFocus End With End Sub
Private Sub Text1_Change() With MSHFlexGrid1 .TextMatrix(m_Row, m_Col) = Text1 End With End Sub
'//**以下是相应的功能函数 ' '加载一个文件到表格. '函数:LoadFileToGrid '参数:MsgObj Mshfelxgrid控件名,FileName 加载的文件名 '返回值:=True 成功.=True 失败. Public Function LoadFile(MsgObj As Control, FileName As String) As Long Dim InputID As Long, FileID As Long Dim EndRow As Long, DltAdd As Long Dim AddFlag As Boolean Dim KeyTab As String, KeyEnter As String Dim FixedRows As Long, FixedCols As Long Dim GridInput As String, AddSum As String, RowColMax() As String Dim GridColMax As Long, GridRowMax As Long Dim OleRow As Long, OleCol As Long Dim SumFmtStr As String Dim DltCol As Long
On Error Resume Next
With MsgObj .Redraw = False Err.Clear: SetAttr FileName, 0 If Err.Number <> 0 Then '如果文件不存在 Err.Clear Call SaveFile(MsgObj, FileName) .Redraw = True Exit Function End If
.Row = .FixedRows .Col = .FixedCols .RowSel = .FixedRows .ColSel = .FixedCols End With End Function
' '保存表格数据 '函数:SaveFile '参数:MsgObj Mshfelxgrid控件名,FileName 加载的文件名 '返回值:=True 成功.=True 失败. Public Function SaveFile(MsgObj As Control, FileName As String) As Boolean '/保存文件 Dim FileID As Long, ConTents As String Dim A As Long, B As Long Dim RowMax As Long, ColMax As Long Dim FixRows As Long, FixCols As Long Dim OleRow As Long, OleCol As Long Dim SFmtStr As String Dim strColWidth As String