老朋友---MSHFlexGrid1

 前言:

     在学生管理系统中初次结识--MSHFlexGrid1 控件,感觉它只是对查询数据的分类显示。在机房收费系统中,再次和它相识,感觉他功能真的很强大的,现在来慢慢的揭开它一层薄薄的面纱吧。害羞

  内容:

       首先,介绍一下常用属性吧。

       CellAlignment Integer 设置/返回一个值以定义当前单元的水平和垂直对齐方式

  CellBackColor Ole_Color 定义当前单元的字体是否为粗体

  CellFontBold Boolean 定义当前单元的字体是否为粗体

  CellFontItalic Boolean 定义当前单元的字体是否为斜体

  CellFontName String 定义当前单元的字体名

  CellFontSize String 定义当前单元的字体大小

       ColAlignment Array/Integer 设置/返回当前列的对齐方式

       Rows Long 返回网格的行的总数或者或BAND的行的总数

  随后介绍一些他的常用功能吧!

1)  MSHFlexGrid1 中的数据导出到EXECEL中   

 '导出数据
        Dim i As Integer
        Dim j As Integer
        myflexgrid.Redraw = False '关闭表格重画
        
        Set xlApp = CreateObject("Excel.Application")  '创建EXCEL对象
        '打开已经存在的excel工作薄文件
        Set xlBook = xlApp.Workbooks.Open(App.Path & "\新建 Microsoft Excel 工作表.xlsx")
        xlApp.Visible = True '设置excel对象可见
        
        Set xlSheet = xlBook.Worksheets("Sheet1")  '设置活动工作表
        
        For i = 0 To myflexgrid.Rows - 1 '行循环
            For j = 0 To myflexgrid.Cols - 1 '列循环
                myflexgrid.Row = i
                myflexgrid.Col = j
                '保存到EXCEL
            xlBook.Worksheets("Sheet1").Cells(i + 1, j + 1) = myflexgrid.Text
            Next j
        Next i
            myflexgrid.Redraw = True

    (2)删除选中的一行;

Dim mrc1 As ADODB.Recordset
Dim mrc2 As ADODB.Recordset
txtsql = "select*from user_info where userid='" & MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 0) & "'"
Set mrc1 = ExecuteSQL(txtsql, msgtext)
txtsql = "select * from onwork_info"
Set mrc2 = ExecuteSQL(txtsql, msgtext)
If Trim(mrc1.Fields(0)) = Trim(mrc2.Fields(0)) Then
   MsgBox "不能删除当前用户!"
   Else
mrc1.Delete
mrc1.Update
mrc1.Close
MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
MsgBox "删除完毕!"
End If

(3)选中某一行进行修改

'通过判断卡号这列是否为数字,来判断是否选中了记录
    If Not IsNumeric(Trim(myflexgrid.TextMatrix(myflexgrid.Row, 2))) Then
         frmModifyinformation.Show
        Exit Sub
    Else
        MsgBox "没有选定要修改的内容", vbOKOnly, "提示!"
        Exit Sub
    End If


      在后面的学习中还会遇见它很多次,每次肯定有不一样的收获,我们一起慢慢的发现吧! 微笑 微笑



你可能感兴趣的:(老朋友---MSHFlexGrid1)