我正好写了一段在MSHFlexGrid代码,给你看看,是否在DataGrid 中可行。 With MSHFlexGrid1
Dim i As Integer i = 0
For i = .FixedRows + 1 To .Rows - 1 Step 2
.Row = i
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols
.CellBackColor =&HC0C0C0 ' light grey
Next i
end with
Dim i As Integer i = 0
For i = .FixedRows + 1 To .Rows - 1 Step 2
.Row = i
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols
.CellBackColor =&HC0C0C0 ' light grey
Next i
end with
Dim i As Integer
i = 0
For i = .FixedRows + 1 To .Rows - 1 Step 2
.Row = i
.Col = .FixedCols
.ColSel = .Cols() - .FixedCols
.CellBackColor = &HCCFFCC '&HC0C0C0 ' light grey
Next i
End With
'*********************************************************
'* 名称:FlexRedraw
'* 功能:表格的标题行(首行)的格式化
'* 用法:FlexRedraw(控件名)
'*********************************************************
Public Function FlexRedraw(F As MSHFlexGrid) As String
With F
.Redraw = False '禁止重画,防止闪动
.BackColorFixed = RGB(190, 218, 178) '标题行背景色
.Row = 0 '设置标题行文字的对其方式
.Col = 0
.ColSel = .Cols - 1
.CellForeColor = vbBlue '标题行文字颜色
.CellAlignment = 4 '对其方式为中间中间
.ScrollTrack = True '移动滚动条的同时数据也滚动
For I = .FixedRows To .Rows - 1 '单双行表格条纹背景色显示
.Row = I '选择第I行
.Col = .FixedCols
.ColSel = .Cols - 1
If I / 2 = Int(I / 2) Then '判断是单是双
.CellBackColor = RGB(224, 248, 224) '双行的底色
Else
.CellBackColor = RGB(240, 248, 224) '单行的底色
End If
Next I
.Row = 1
.Col = 1
.ColSel = .Cols - 1
.Redraw = True '允许重画,显示表格
End With
End Function
'*********************************************************
'* 名称:FlexRedraw
'* 功能:表格的标题行(首行)的格式化
'* 用法:FlexRedraw(控件名)
'*********************************************************
Public Function FlexRedraw(F As MSHFlexGrid) As String
With F
.Redraw = False '禁止重画,防止闪动
.BackColorFixed = RGB(190, 218, 178) '标题行背景色
.Row = 0 '设置标题行文字的对其方式
.Col = 0
.ColSel = .Cols - 1
.CellForeColor = vbBlue '标题行文字颜色
.CellAlignment = 4 '对其方式为中间中间
.ScrollTrack = True '移动滚动条的同时数据也滚动
For I = .FixedRows To .Rows - 1 '单双行表格条纹背景色显示
.Row = I '选择第I行
.Col = .FixedCols
.ColSel = .Cols - 1
If I / 2 = Int(I / 2) Then '判断是单是双
.CellBackColor = RGB(224, 248, 224) '双行的底色
Else
.CellBackColor = RGB(240, 248, 224) '单行的底色
End If
Next I
.Row = 1
.Col = 1
.ColSel = .Cols - 1
.Redraw = True '允许重画,显示表格
End With
End Function