只能隔行/列循环,每个循环里,对列/行循环,再设置单元格的背景色 private sub SetColor(grd as mshflexgrid,Color as long,bByRow as boolean)dim loop1 as long dim loop2 as long dim lstart1 as long dim lstart2 as long dim I as long,J as longif bByrow then loop1=grd.rows-1 loop2=grd.cols-1 lstart1=grd.fixedrows lstart2=grd.fixedcols else loop1=grd.cols-1 loop2=grd.rows-1 lstart1=grd.fixedcols lstart2=grd.fixedrows endif for i=lstart1 to loop1 step 2 if bbyrow then grd.row=i else grd.col=i endif for j=lstart2 to loop2 if bbyrow then grd.col=j else grd.row=j endif grd.cellbackcolor=color next j next i end sub
Public Sub set_hflexgrid(thisform As Form) Dim i% Dim j% With thisform.Dg_query .Redraw = False .BackColorFixed = &HC0D3C1 For i = 1 To .Rows - 1 .Row = i For j = 0 To .Cols - 1 .col = j
If .Row Mod 2 = 0 Then .CellBackColor = &HE0E0E0
Else .CellBackColor = &HC0E0FF End If Next Next i .Redraw = True End With End Sub
'设置网格隔行颜色 Public Sub SetGridColor(grdNow As MSFlexGrid) DoEvents On Error Resume Next Dim TempCol As Long, TempRow As Long With grdNow If .Rows <= 2 Then Exit Sub TempCol = .Col TempRow = .Row .Redraw = False .FillStyle = flexFillRepeat .Row = .FixedRows .Col = .FixedCols .ColSel = .Cols - 1 .CellBackColor = ccRowBackColor1 '&HDAE9EC 'ccRowBackColor2 ' 隔行变灰 Dim iLoop As Integer For iLoop = .FixedRows + 1 To .Rows - 1 .Row = iLoop .Col = .FixedCols If .FixedCols = 0 Then .ColSel = .Cols() - .FixedCols - 1 Else .ColSel = .Cols() - .FixedCols End If
If iLoop Mod 2 = 0 Then .CellBackColor = &HDAE9EC ' 浅灰 Else .CellBackColor = ccRowBackColor1 'ccRowBackColor2 ' 浅灰 End If Next iLoop .FillStyle = flexFillSingle If .Cols - 1 >= TempCol Then .Col = TempCol If .Rows - 1 >= TempRow Then .Row = TempRow .Redraw = True End With End Sub
private sub SetColor(grd as mshflexgrid,Color as long,bByRow as boolean)dim loop1 as long
dim loop2 as long
dim lstart1 as long
dim lstart2 as long
dim I as long,J as longif bByrow then
loop1=grd.rows-1
loop2=grd.cols-1
lstart1=grd.fixedrows
lstart2=grd.fixedcols
else
loop1=grd.cols-1
loop2=grd.rows-1
lstart1=grd.fixedcols
lstart2=grd.fixedrows
endif
for i=lstart1 to loop1 step 2
if bbyrow then
grd.row=i
else
grd.col=i
endif
for j=lstart2 to loop2
if bbyrow then
grd.col=j
else
grd.row=j
endif
grd.cellbackcolor=color
next j
next i
end sub
Dim i%
Dim j%
With thisform.Dg_query
.Redraw = False
.BackColorFixed = &HC0D3C1
For i = 1 To .Rows - 1
.Row = i
For j = 0 To .Cols - 1
.col = j
If .Row Mod 2 = 0 Then
.CellBackColor = &HE0E0E0
Else
.CellBackColor = &HC0E0FF
End If
Next
Next i
.Redraw = True
End With
End Sub
Public Sub SetGridColor(grdNow As MSFlexGrid)
DoEvents
On Error Resume Next
Dim TempCol As Long, TempRow As Long
With grdNow
If .Rows <= 2 Then Exit Sub
TempCol = .Col
TempRow = .Row
.Redraw = False
.FillStyle = flexFillRepeat
.Row = .FixedRows
.Col = .FixedCols
.ColSel = .Cols - 1
.CellBackColor = ccRowBackColor1 '&HDAE9EC 'ccRowBackColor2
' 隔行变灰
Dim iLoop As Integer
For iLoop = .FixedRows + 1 To .Rows - 1
.Row = iLoop
.Col = .FixedCols
If .FixedCols = 0 Then
.ColSel = .Cols() - .FixedCols - 1
Else
.ColSel = .Cols() - .FixedCols
End If
If iLoop Mod 2 = 0 Then
.CellBackColor = &HDAE9EC ' 浅灰
Else
.CellBackColor = ccRowBackColor1 'ccRowBackColor2 ' 浅灰
End If
Next iLoop
.FillStyle = flexFillSingle
If .Cols - 1 >= TempCol Then .Col = TempCol
If .Rows - 1 >= TempRow Then .Row = TempRow
.Redraw = True
End With
End Sub
用这ColWidth属性改变宽度
要隔行设置应该不行,这种控件做成那样也很难看的。
实在需要那样的话就只有用单元格代替了。