Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1609
  • Last Modified:

color cells in a msFlexgrid based on cell contents using vb6

group rows by color
i am trying to determine how to write code to group colors of cells that have the same file name in the first column Col 0 using a msflexgrid.
eg; if the row has the same file name the the color of the rows will all be the same until the filename changes then a different color
1 Solution
Try this:

Private Sub Command1_Click()

  Dim c As Long
  Dim r As Long
  Dim sC0 As String
  Dim nColor As Long
  Dim bTogleColor As Boolean
  c = 0
  With MSFlexGrid1
    '/ Sort Grid by Column 0
    .Col = c
    .ColSel = 0
    .Sort = flexSortGenericAscending

    sC0 = vbNullString
    bTogleColor = False
    nColor = GetColor(bTogleColor)
    For r = 1 To .Rows - 1
          If Len(.TextMatrix(r, 0)) > 0 Then
              If r = 1 Then
                  .Row = r
                  .Col = c
                  .CellBackColor = nColor
                  sC0 = .TextMatrix(r, 0)
                  If CheckRow(r, sC0) = False Then
                      bTogleColor = Not bTogleColor
                      nColor = GetColor(bTogleColor)
                      sC0 = .TextMatrix(r, 0)
                  End If
                  .Row = r
                  .Col = c
                  .CellBackColor = nColor
              End If
          End If

  End With

End Sub

Private Function CheckRow( _
                    ByVal nRow As Long, _
                    ByVal sC0 As String _
                    ) As Boolean
  With MSFlexGrid1
      If nRow <= .Rows - 1 Then
          If (Trim(.TextMatrix(nRow, 0)) = Trim(sC0)) Then
              CheckRow = True
          End If
      End If
  End With
  Exit Function

End Function

Private Function GetColor( _
                    ByVal bTogleColor As Boolean _
                    ) As Long
  GetColor = RGB(255, 100 * Abs(bTogleColor), 100)
  Exit Function

End Function

Open in new window

isnoend2001Author Commented:
thank you
That works
Hishamullah AlweeIT TechnicalCommented:
I want to create two colors in 1 column (Remark Section) based on three situations :
Situation 1 : If Total Weight is Over than Upperlimit, will come out RED Color (Backcolor)
                    If Wt >= RsParts.Fields!Upperlimit Then
                    LowerUpper "This Part Weight is OVER than UpperLimit"

Situation 2 : If Total Weight is LESS than Lowerlimit, will come out RED Color (Backcolor)
                    If Wt <= RsParts.Fields!Lowerlimit Then
                    LowerUpper "This Part Weight is LESS than Lowerlimit"

Situation 3 : If Total Weight is OK (In Spec), will come out GREEN Color (Backcolor)
                    If Wt <> RsParts.Fields!Upperlimit or Wt<>RsParts.Fields!Lowerlimit then
                     LowerUpper "This Part Weight is OK !"

So, when each time calibrate with Weighing Machine then display output (LowerLimit, Upperlimit or OK (In Spec)) at MsFlexGrid, I want to show 2 Colors in 1 Column only based on 3 situations.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now