用循环语句对msflexgrid的每一行每一列分别格式化!

解决方案 »

  1.   

    只能隔行/列循环,每个循环里,对列/行循环,再设置单元格的背景色
    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
      

  2.   

    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
      

  3.   

    vb6的帮助文件里有一些是教你如何改变mshflexgrid的背景颜色的,你自己去看一下,如果想改格线,没有试过。关注!
      

  4.   

    Why not use vsflexgrid ?
      

  5.   

    MSHFlexGrid 的栅格线的宽度或者颜色好象是可以指定的吧,找找他的属性
      

  6.   

    改变MSHFlexGrid的某一个单元格的色彩也不很方便,我使用过北京EHD系统和益华系统,都做得很好,但它们都是用PowerBuilder编的。
      

  7.   

    '设置网格隔行颜色
    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
      

  8.   

    MSFlexGrid1.ColWidth(0) = 1600
    用这ColWidth属性改变宽度
      

  9.   

    GridLineWidth可以改变跚格的宽度。
    要隔行设置应该不行,这种控件做成那样也很难看的。
    实在需要那样的话就只有用单元格代替了。