[VB6]MSFlexGrid使用記錄

- 設定
Components加入MSFlexGrid
Microsoft FlexGrid Control 6.0 (SP6)
C:\Windows\SysWow64\MSFLXGRD.OCX

加入後即在
Component Panel上出現MSFlexGrid的控件 (紅框處)
Form上建立MSFlexGrid控件對控件按右鍵可設置其Property

Common Property
Style Property
 Font Property
 Color Property
 Picture Property
Code中設置Property較有彈性, 故於選單中的屬性怒不設定


- 記錄
' configuration property of MSFLESGRID1
With MSFlexGrid1
    .AllowBigSelection = False
    .ColAlignment(-1) = flexAlignCenterCenter
    .FixedCols = 0
    .FixedRows = 1
    .HighLight = flexHighlightNever
    .ScrollBars = flexScrollBarVertical
    .ScrollTrack = True
End With
  • Property AllowBigSelection As Boolean
Row / Column點選Header, 全選該Rows Columns

  • Property ColAlignment(index As Long) As Integer
指定Columns的文字對齊, -1表設置全部Columns

  • Property FixedCols As Long
  • Property FixedRows As Long
指定Header的數量

  • Property HighLight As HighLightSettings
設定圈選欄位時是否HighLight

  • Property ScrollBars As ScrollBarsSettings
設定ScrollBars的顯示

  • Property ScrollTrack As Boolean
拉動ScrollBars, 是否即時顯示內容


With MSFlexGrid1
    ' Set the Dimension for Row & Column
    .Cols = 6
    .Rows = size + 1 ' Add the Position of Title(idx=0)



    ' Fixed Row Position 
    .TopRow = 1



    ' Set the Width of Columns (Balance Width)
    For i = 0 To (.Cols - 1)
        .ColWidth(i) = .width / .Cols
    Next



    ' Content of Header
    posTitle = 0    ' start from idx=0
    .TextMatrix(posTitle, 0) = selVoltage & Space(1) & convBitPos(regBit(cmd, reg))
    .TextMatrix(posTitle, 1) = "Voltage(V)"
    .TextMatrix(posTitle, 2) = "V(Meas.)"
    .TextMatrix(posTitle, 3) = "I(Meas.)"
    .TextMatrix(posTitle, 4) = "V-Shift"

    ' Set the Bold Property for Header
    .row = posTitle
    For i = 0 To (.Cols - 1)
        .col = i
        .CellFontBold = True
    Next



    ' Insert Data
    posData = 1     ' start form idx=1
    For i = 0 To (size - 1)
        .row = i + posData

        .TextMatrix(i + posData, 0) = IntToBin(a_regData(i), convBitLen(regBit(cmd, reg))) & "b"
        .TextMatrix(i + posData, 1) = a_regValue(i)
        .TextMatrix(i + posData, 2) = a_regVmeas(i)
        .TextMatrix(i + posData, 3) = a_regImeas(i)
        .TextMatrix(i + posData, 4) = a_regVshift(i)
        
        ' 背景交替顏色
        If i Mod 2 <> 0 Then
            For j = 0 To (.Cols - 1)
                .col = j
                .CellBackColor = &H80FFFF
            Next
        End If
    Next
End With

  • Property Cols As Long
  • Property Rows As Long
設定或取得Column / Row的數量

  • Property TopRow As Long
設置顯示的位置

  • Property ColWidth(index As Long) As Long
設置Column的寬度

  • Property Width As Single
整個MSFlexGrid控件的寬度

  • Property TextMatrix(Row As Long, Col As Long) As String
填入/讀取Cell的內容

  • Property CellFontBold As Boolean
設定當前Cell的文字是否為粗體 (須搭配Col/Row指定Cell)

  • Property CellBackColor As OLE_COLOR
設置Cell的背景顏色 (須搭配Col/Row指定Cell)



With MSFlexGrid1
    For i = 0 To 10
        .AddItem "INDEX_" & i & vbTab & "Test" & vbTab & "by Martin"
    Next
End With

  • Sub AddItem(Item As String, [index])
連續寫入資料使用vbTab字元分離不同Columns, Index指定插入哪一個Row


Ref:

留言

這個網誌中的熱門文章

[VB6]使用File Dialog選擇檔案