VSFlexGrid 使之无如何单元点击框

VSFlexGrid1.FocusRect = 0
VSFlexGrid1.HighLight = 0

'------------------VSFlexGrid--平面效果备忘-----此设置会增加表格外观效果--特别是合并固定列后-------

VSFlexGrid1.GridColorFixed = RGB(0, 200, 200)
 VSFlexGrid1.BackColorFixed = RGB(200, 200, 200)

VSFlexGrid1.Appearance = flexFlat  '边框平面 =0
VSFlexGrid1.GridLinesFixed = flexGridFlat '平面网格线类型flexGridFlat =1

'----------------固定列合并-------

VSFlexGrid1.MergeCells = 5 '只合并固定行列

VSFlexGrid1.MergeCells = 4

VSFlexGrid1.MergeCells = 3 '只合并固定行

'------------在全选时使某行无选择颜色标记----------------

Private Sub VSFlexGrid1_BeforeRowColChange(ByVal OldRow As Long, ByVal OldCol As Long, ByVal NewRow As Long, ByVal NewCol As Long, Cancel As Boolean)

'本事件发生在Row未改变前
    If NewRow = 2 Then
        VSFlexGrid1.SelectionMode = flexSelectionFree
    Else
        VSFlexGrid1.SelectionMode = flexSelectionByRow
    End If
End Sub

 

'----------------VSFlexGrid---重绘----------------------------------

Private Sub Form_Load()
VSFlexGrid1.OwnerDraw = flexODComplete
End Sub

Private Sub VSFlexGrid1_DrawCell(ByVal hDC As Long, ByVal Row As Long, ByVal Col As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long, Done As Boolean)
Debug.Print "Row: " & Row & "   Col: " & Col & " Left " & Left & "  Top " & Top & "  Right " & Right

如果 Done = True 则控件就什么都不绘制,全部由用户自己绘制
End Sub

'-------------使用重绘事件--监控新增行事件----主要是在对象赋值后判断对象是否有新增时使用---------------------

Dim RowsC As Long
Private Sub Command1_Click()
VSFlexGrid1.AddItem ""
End Sub

Private Sub Form_Load()
VSFlexGrid1.Rows = 2
VSFlexGrid1.OwnerDraw = flexODComplete  '自绘
End Sub
Private Sub VSFlexGrid1_DrawCell(ByVal hDC As Long, ByVal Row As Long, ByVal Col As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long, Done As Boolean)
   '自绘事件
   If VSFlexGrid1.Rows <> RowsC Then
        Debug.Print "有新增行事件-当前总行数: " & VSFlexGrid1.Rows
        RowsC = VSFlexGrid1.Rows
    End If
End Sub

'-------------------使用 VSFlexNode 节点对象添加节点-----------------------------------------


Private Sub Command1_Click()
On Error Resume Next

    Dim nd As VSFlexNode
    Set nd = fg.GetNode
   
  If Err.Number = 381 Then
    MsgBox "请选择要添加下级的行"
  Else
   
    nd.AddNode 2, "一cvb"
    With fg
        '.TextMatrix(fg.Row + 1, 0) = "一"
        .TextMatrix(fg.Row + 1, 1) = "临时工程"
        .TextMatrix(fg.Row + 1, 2) = "公路公里"
        .Cell(flexcpAlignment, .Row + 1, 0, .Row + 1, .Cols - 1) = flexAlignLeftCenter '填充数据左对齐
    End With
 End If

End Sub

 

Private Sub Form_Load()
   
    ' initialize grid
    With fg
        .WordWrap = True  '设定单元中的文本是否换行
        ' layout
        .Rows = 1
        .Cols = 3
        .FixedCols = 0
        .ColWidth(0) = 1000
        .ColWidth(1) = 3000
        .ColWidth(2) = 1000
        .RowHeight(0) = 500
        '.ExtendLastCol = True '是否扩充最后的列到适合宽度
        .TextMatrix(0, 0) = "编号"
        .TextMatrix(0, 1) = "名称"
        .TextMatrix(0, 2) = "单位"
 
       
        .Editable = flexEDKbdMouse '设置表格是否可编辑修改

        .AddItem "" & vbTab & "第一部分 第100章至第700章" & vbTab & "公路公里"
        .IsSubtotal(fg.Rows - 1) = True
        .RowOutlineLevel(fg.Rows - 1) = 1
        ' outline
        .OutlineCol = 0

        .OutlineBar = flexOutlineBarSimpleLeaf '设置显示目录树的线条
        .MergeCells = flexMergeFixedOnly '相同内容的单元格合并类型

        .Cell(flexcpFontBold, 1, 0, 1, .Cols - 1) = True '填充数据加粗
        .Cell(flexcpAlignment, 1, 0, 1, .Cols - 1) = flexAlignLeftCenter '填充数据左对齐

        ' other
        .AllowUserResizing = flexResizeColumns '调整(行/列)大小方式
        .AllowSelection = False
        .GridLines = flexGridFlatHorz '可编辑区的网格线类型

         'fg.AutoSize 0, 1, , 200
        fg.Redraw = flexRDBuffered
    End With

End Sub

你可能感兴趣的:(VSFlexGrid 使之无如何单元点击框)