mshflexgrid控件中,如图实现表头合并,单元格不合并
mshflexgrid控件中,如何实现表头列合并,单元格不合并。如:
表头: 8月15日 欠休数
星期一 欠休数
表格: 张三 3
李四 3
要求表头的欠休数合并,但表格的3不合并 数据的偶数行在数据字符串前后各加上一个 Chr(255) 不可见字符(对于居中对齐):
Private Sub Form_Load()你这种解决办法只适合行数比较少得情况,我是从数据库中调用的数据,所有行数比较多,没办法一条一条的加呀,求解决方案,谢谢大神!!! 大神不回复,自己帮顶!!!!!!!!!!!!!!!!!!!!!!!! 你可以只处理显示出来的部分试试,类似这样:
With MSFlexGrid1
.Cols = 2
.Rows = 0
.AddItem "8月15日" & vbTab & "欠休数", 0
.AddItem "星期一" & vbTab & "欠休数", 1
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & Chr(255) & "3" & Chr(255)
.FixedCols = 0
.FixedRows = 2
.ColAlignment(0) = 4
.ColAlignment(1) = 4
.MergeCells = flexMergeRestrictColumns
.MergeCol(1) = True
End With
End Sub
Private Sub Form_Load()在Scroll事件中写代码填充左右两边的特殊字符。
With MSHFlexGrid1
.Cols = 2
.Rows = 0
.AddItem "8月15日" & vbTab & "欠休数", 0
.AddItem "星期一" & vbTab & "欠休数", 1
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.AddItem "张三" & vbTab & "3"
.AddItem "李四" & vbTab & "3"
.FixedCols = 0
.FixedRows = 2
.ColAlignment(0) = 4
.ColAlignment(1) = 4
.MergeCells = flexMergeRestrictColumns
.MergeCol(1) = True
End With
Call MSHFlexGrid1_Scroll
End Sub
Private Sub MSHFlexGrid1_Scroll()
Dim i As Long
With MSHFlexGrid1
For i = .TopRow To .Rows - 1
If .RowData(i) <> 1 Then
If i Mod 2 = 0 Then
.TextMatrix(i, 1) = " " & .TextMatrix(i, 1) & " "
End If
.RowData(i) = 1 '标记一下,这行已经处理过了,下次再显示这一行就别再加空格了
End If
Next
End With
End Sub
上面的写错了,漏了一个条件
Private Sub MSHFlexGrid1_Scroll()
Dim i As Long
With MSHFlexGrid1
For i = .TopRow To .Rows - 1
If .RowIsVisible(i) And .RowData(i) <> 1 Then
If i Mod 2 = 0 Then
.TextMatrix(i, 1) = " " & .TextMatrix(i, 1) & " "
End If
.RowData(i) = 1 '标记一下,这行已经处理过了,下次再显示这一行就别再加空格了
End If
Next
End With
End Sub
补充:VB , 控件