MsHFlexGrid如何在不选中的情况下,去改变某一单元格的背景色,急!!!

handyworkroom 2003-08-24 10:09:24
过去用选中某一行,然后改变选中单元格的背景色,当需要改变的单元格太多时,这样很麻烦,而且格子还可能闪动。
所在想问一下,有没有好的办法,在不选中的情况下,去改变单元格的背景色。
...全文
200 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
didishu0807 2003-08-27
  • 打赏
  • 举报
回复
MSHFlexGrid1.Col = 1
MSHFlexGrid1.Row = 1
MSHFlexGrid1.CellBackColor = vbRed
wumy_ld 2003-08-26
  • 打赏
  • 举报
回复
'设置网格控件颜色
Public Sub SetMSHFlexGridColor(ByRef mshGrid As mshFlexGrid)
Dim i As Long, j As Integer
With mshGrid
For i = 1 To mshGrid.Rows - 1
.Row = i
For j = 0 To mshGrid.Cols - 1
.Col = j
If i Mod 2 = 1 Then
.CellBackColor = vbInfoBackground
Else
.CellBackColor = RGB(255, 255, 255)
End If
Next j
DoEvents '刷完每一行之后稍停
Next i
.Refresh
End With
End Sub
liul17 2003-08-25
  • 打赏
  • 举报
回复
你可以使用复选机制,使Msflexgrid的第1列为复选列。
给你个例子(在窗体上要有个ImageList,其中有2个Icon,一个勾的一个不勾的)
Private Sub grdList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'点击第0列的复选框决定是否为明细级记录
Dim lCrow As Long, lCcol As Long


'无合同不得编辑
If lvwItem.ListItems.Count <= 0 Then Exit Sub



With grdList
If clsPrj.colL_Project.Item(.Row).sParent <> "-1" And clsPrj.colL_Project.Item(.Row).sParent <> gsNULL Then Exit Sub
If clsPrj.colL_Project.Item(.Row).bNew Then
'Call CalRC(x, y, lCrow, lCcol)
lCrow = HitRow(grdList, Y)
lCcol = HitCol(grdList, X)

'存在下级后不得直接修改明细、非明细
If clsPrj.colL_Project.Item(grdList.Row).iSubLevels > 0 Then Exit Sub

If lCcol = -1 Then
.Col = 0
If clsPrj.colL_Project.Item(.Row).bLastLevel Then
Set .CellPicture = imglPic.ListImages.Item("uncheck2").Picture
clsPrj.colL_Project.Item(.Row).bLastLevel = False
Else
Set .CellPicture = imglPic.ListImages.Item("check2").Picture
clsPrj.colL_Project.Item(.Row).bLastLevel = True
End If
bFinishIni = False
.Col = .FixedCols
bFinishIni = True
End If

End If

End With
End Sub


'返回当前给定y坐标在MSFlexGrid中的第几行
Public Function HitRow(grd As MSFlexGrid, ByVal Y As Single) As Long
Dim lRow As Single

With grd
For lRow = .TopRow To .Rows - 1
If Y > .RowPos(lRow) And Y <= .RowPos(lRow) + .RowHeight(lRow) Then
HitRow = lRow
Exit Function
End If
Next lRow
End With
HitRow = -1
End Function
'返回当前给定x坐标在MSFlexGrid中的第几列
Public Function HitCol(grd As MSFlexGrid, ByVal X As Single) As Long
Dim lCol As Single

With grd
If X <= .ColPos(.leftCol) Then
HitCol = -1
Exit Function
End If

For lCol = .leftCol To .Cols - 1
If X > .ColPos(lCol) And X <= .ColPos(lCol) + .ColWidth(lCol) Then
HitCol = lCol
Exit Function
End If
Next lCol
HitCol = -2
End With
End Function


Apple200228 2003-08-24
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Me.MSHFlexGrid1.Col = 2
Me.MSHFlexGrid1.Row = 2
Me.MSHFlexGrid1.CellBackColor = vbRed
End Sub

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧