VB6.0下怎么在MSHFlexGrid实现条件格式
1个回答
展开全部
MSHFlexGrid不能像excel和Access那样用设置条件格式的方法来展示数据的外观。
如果需要突显数据,只能通过代码根据数据内容逐行、逐单元设置进行设置MSHFlexGrid控件的各种属性(如调整字体、前\后背景色、对齐方式、添加特殊图标等)来凸显数据。只要应用的好,其展示数据的效果不会差于条件格式甚至更好。注意为了提高显示速度,建议设置格式时先将MSHFlexGrid的Redraw属性设置为False,全部单元格都设置完毕后再设置为True以显示最新设置后的数据外观。这样做的好处是可以大大地提高反应速度,根据本人的经验,用代码设置数据显示外观的速度是非常快的,完全能满足一般的要求。对于十分巨大的数据集为了减少反应时间,可以考虑实施分页显示。
下面提供一个设置MSHFlexGrid显示外观的Sub过程实例供参考
Private Sub FillDsMshflx(rst As ADODB.Recordset, Mshflx As MSHFlexGrid)
Dim i As Long, j As Byte
With Mshflx
.ClearStructure
.Rows = 2
.Cols = 2
LblCountDsSr.Caption = ""
LblSfQk(0).Caption = ""
LblCountDsZc.Caption = ""
LblSfQk(3).Caption = ""
.Redraw = False
.Cols = 13
.FixedCols = 3
.BackColorFixed = vbCyan
.BackColorBkg = 8421504
.Font.Size = 9
.ColWidth(0) = 0.5 * 567
.ColWidth(1) = 2.1 * 567
.TextMatrix(0, 1) = "本社编号"
.ColWidth(2) = 0.8 * 567
.TextMatrix(0, 2) = "结讫"
.ColWidth(3) = 1.8 * 567
.TextMatrix(0, 3) = "日期"
.ColWidth(4) = 4.6 * 567
If Mshflx.Name = "MSHFlexGridDsSr" Then
.TextMatrix(0, 4) = "收款项目"
Else
.TextMatrix(0, 4) = "付款项目"
End If
.ColWidth(5) = 0.8 * 567
.TextMatrix(0, 5) = "数量"
.ColWidth(6) = 0.8 * 567
.TextMatrix(0, 6) = "货币"
.ColWidth(7) = 1.2 * 567
.TextMatrix(0, 7) = "单价"
.ColWidth(8) = 1.8 * 567
.TextMatrix(0, 8) = "金额"
.ColWidth(9) = 0.8 * 567
.TextMatrix(0, 9) = "类型"
.ColWidth(10) = 1.2 * 567
.TextMatrix(0, 10) = "现金户"
.ColWidth(11) = 0.8 * 567
.TextMatrix(0, 11) = "位置"
.ColWidth(12) = 1.2 * 567
.TextMatrix(0, 12) = "ID"
.Row = 1
.Col = 1
.CellBackColor = vbWhite
.Col = 2
.CellBackColor = vbWhite
.Col = 3
.CellBackColor = vbWhite
i = 1
If Not rst.BOF And Not rst.EOF Then '根据字段内容突显数据
Do Until rst.EOF
For j = 1 To 12
If i > 1 Then .Rows = i + 1
.Row = i
.Col = j
If j = 1 Then
.Text = rst!BSBH
.CellBackColor = vbWhite
If rst!Xg = "现结" Then .CellForeColor = vbBlue
End If
If j = 2 Then
If rst!Jq = True Then
.Text = " "
Set .CellPicture = frmBack.ImgChecked.Picture
Else
.Text = ""
Set .CellPicture = frmBack.ImgUnChecked.Picture
End If
.CellPictureAlignment = flexAlignCenterCenter
.CellBackColor = vbWhite
End If
If j = 3 Then
.Text = Format(rst!rq, "yyyy-mm-dd")
If rst!Xg = "现结" Then .CellForeColor = vbBlue
End If
If j = 4 Then
.Text = rst!xm
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignLeftCenter
End If
If j = 5 Then
.Text = rst!SL
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignCenterCenter
End If
If j = 6 Then
.Text = rst!Hb
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignCenterCenter
End If
If j = 7 Then
.Text = rst!Je
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignRightCenter
End If
If j = 8 Then
.Text = rst!HJ
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignRightCenter
End If
If j = 9 Then
.Text = rst!Xg
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignLeftCenter
End If
If j = 10 Then
.Text = IIf(IsNull(rst!xsh), "", rst!xsh)
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignLeftCenter
End If
If j = 11 Then
.Text = IIf(IsNull(rst!WZ), "", rst!WZ)
If rst!Xg = "现结" Then .CellForeColor = vbBlue
.CellAlignment = flexAlignLeftCenter
End If
If j = 12 Then .Text = rst!ID
Next j
rst.MoveNext
i = i + 1
Loop
End If
.Col = 2
.Row = 1
.Redraw = True
If .TextMatrix(1, 1) <> "" Then
.TextMatrix(1, 0) = "●"
End If
End With
Call setMshflxDsSrPos("Right")
Call ShowDsKhSr(True)
Call ShowDsKhZc(True)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询