老大,请这看这段代码(转载的)吧,可能对你有点帮助的! '********************************************************************* '* 改变grid颜色,把单数行和双数行的颜色设置成不同的颜色! '********************************************************************* Public Sub SetGridColor(TheGrid As Control, row_col As Boolean, RowsColor As Long, ColsColor As Long) Dim i As Integer Dim J As Integer Dim k As Long
If row_col Then For J = TheGrid.FixedRows To TheGrid.Rows - 1 If k = ColsColor Then k = RowsColor Else k = ColsColor End If
For i = TheGrid.FixedCols To TheGrid.Cols - 1 TheGrid.Row = J: TheGrid.Col = i TheGrid.CellBackColor = k TheGrid.CellForeColor = &H80000008 Next Next TheGrid.Row = 0 For i = 0 To TheGrid.Cols - 1 TheGrid.Col = i TheGrid.CellAlignment = 4 Next TheGrid.Redraw = True Else For J = TheGrid.FixedCols To TheGrid.Cols - 1 If k = ColsColor Then k = RowsColor Else k = ColsColor End If
For i = TheGrid.FixedRows To TheGrid.Rows - 1 TheGrid.Col = J: TheGrid.Row = i TheGrid.CellBackColor = k TheGrid.CellForeColor = &H80000008 Next Next TheGrid.Col = 0 For i = 0 To TheGrid.Rows - 1 TheGrid.Row = i TheGrid.CellAlignment = 4 Next TheGrid.Redraw = TrueEnd IfEnd Sub
Private Sub hflexgrid_EnterCell() '单击某一单元时,改变该行颜色 Dim i_Col As Integer Dim c_col As Integer c_col = Hflexgrid.Col If c_col > 0 Then For i_Col = 0 To Hflexgrid.Cols - 1 Hflexgrid.Col = i_Col Hflexgrid.CellBackColor = &HFFFFC0 Next i_Col Hflexgrid.Col = c_col End If End SubPrivate Sub hflexgrid_LeaveCell() '当某一行失去焦点时,改变该行颜色 Dim i_Col As Integer Dim c_col As Integer c_col = Hflexgrid.Col For i_Col = 0 To Hflexgrid.Cols - 1 Hflexgrid.Col = i_Col Hflexgrid.CellBackColor = vbWhite Next i_Col Hflexgrid.Col = c_col End Sub
'*********************************************************************
'* 改变grid颜色,把单数行和双数行的颜色设置成不同的颜色!
'*********************************************************************
Public Sub SetGridColor(TheGrid As Control, row_col As Boolean, RowsColor As Long, ColsColor As Long)
Dim i As Integer
Dim J As Integer
Dim k As Long
TheGrid.Redraw = False
TheGrid.BackColorBkg = &H808080
TheGrid.BackColorFixed = &HC0C0C0
If row_col Then
For J = TheGrid.FixedRows To TheGrid.Rows - 1
If k = ColsColor Then
k = RowsColor
Else
k = ColsColor
End If
For i = TheGrid.FixedCols To TheGrid.Cols - 1
TheGrid.Row = J: TheGrid.Col = i
TheGrid.CellBackColor = k
TheGrid.CellForeColor = &H80000008
Next
Next TheGrid.Row = 0
For i = 0 To TheGrid.Cols - 1
TheGrid.Col = i
TheGrid.CellAlignment = 4
Next
TheGrid.Redraw = True
Else
For J = TheGrid.FixedCols To TheGrid.Cols - 1
If k = ColsColor Then
k = RowsColor
Else
k = ColsColor
End If
For i = TheGrid.FixedRows To TheGrid.Rows - 1
TheGrid.Col = J: TheGrid.Row = i
TheGrid.CellBackColor = k
TheGrid.CellForeColor = &H80000008
Next
Next TheGrid.Col = 0
For i = 0 To TheGrid.Rows - 1
TheGrid.Row = i
TheGrid.CellAlignment = 4
Next
TheGrid.Redraw = TrueEnd IfEnd Sub
MSFlexGrid1.SelectionMode = flexSelectionByRow
'单击某一单元时,改变该行颜色
Dim i_Col As Integer
Dim c_col As Integer
c_col = Hflexgrid.Col
If c_col > 0 Then
For i_Col = 0 To Hflexgrid.Cols - 1
Hflexgrid.Col = i_Col
Hflexgrid.CellBackColor = &HFFFFC0
Next i_Col
Hflexgrid.Col = c_col
End If
End SubPrivate Sub hflexgrid_LeaveCell()
'当某一行失去焦点时,改变该行颜色
Dim i_Col As Integer
Dim c_col As Integer
c_col = Hflexgrid.Col
For i_Col = 0 To Hflexgrid.Cols - 1
Hflexgrid.Col = i_Col
Hflexgrid.CellBackColor = vbWhite
Next i_Col
Hflexgrid.Col = c_col
End Sub