VB 中的MSFlexGrid控件,怎样使MSFlexGrid控件中选中的一行改变颜色?
4个回答
展开全部
Private Sub Command1_Click()
MSFlexGrid1.BackColorBkg = vbGreen
End Sub
Private Sub Form_Load()
MSFlexGrid1.Cols = 10
MSFlexGrid1.Rows = 10
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 0
MSFlexGrid1.SelectionMode = flexSelectionByRow
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'On Error GoTo Err_Proc
Dim intCurrCol As Long
intCurrCol = MSFlexGrid1.Col
'单击选择或不选择
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√" Then
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = ""
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = vbWhite
Next i_Col
Else
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√"
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = &H80C0FF
Next i_Col
End If
MSFlexGrid1.Col = intCurrCol
Exit Sub
End Sub
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Me.Caption = MSFlexGrid1.MouseRow & "," & MSFlexGrid1.MouseCol
End Sub
MSFlexGrid1.BackColorBkg = vbGreen
End Sub
Private Sub Form_Load()
MSFlexGrid1.Cols = 10
MSFlexGrid1.Rows = 10
MSFlexGrid1.FixedCols = 0
MSFlexGrid1.FixedRows = 0
MSFlexGrid1.SelectionMode = flexSelectionByRow
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'On Error GoTo Err_Proc
Dim intCurrCol As Long
intCurrCol = MSFlexGrid1.Col
'单击选择或不选择
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√" Then
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = ""
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = vbWhite
Next i_Col
Else
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√"
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = &H80C0FF
Next i_Col
End If
MSFlexGrid1.Col = intCurrCol
Exit Sub
End Sub
Private Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Me.Caption = MSFlexGrid1.MouseRow & "," & MSFlexGrid1.MouseCol
End Sub
追问
这么多代码啊,能不能设个啥属性就可以实现。
追答
不能设个啥属性就可以实现。不要对勾的话只需要以下代码
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If MSFlexGrid1.CellBackColor = &H80C0FF Then
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = vbWhite
Next i_Col
Else
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = &H80C0FF
Next i_Col
End If
End Sub
楼下的,给点代码看看?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要使MSFlexGrid控件中选中的一行改变颜色,必须了解 MSFlexGrid控件的 BackColorSel 属性,该属性是选中单元格时的背景色。具体可以查阅VB的mand文档。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Else
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√"
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = &H80C0FF
Next i_Col
MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) = "√"
'改变行颜色
For i_Col = 0 To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = i_Col
MSFlexGrid1.CellBackColor = &H80C0FF
Next i_Col
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
要方便的改变颜色,选用listtree就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询