Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

color cells in a msFlexgrid based on cell contents using vb6

Posted on 2012-12-28
3
Medium Priority
?
1,563 Views
Last Modified: 2016-10-26
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
gridWinslosses.CellBackColor
0
Comment
Question by:isnoend2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
eemit earned 2000 total points
ID: 38728244
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)
              Else
                  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
    Next

  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

1
 

Author Closing Comment

by:isnoend2001
ID: 38728528
thank you
That works
0
 

Expert Comment

by:Hishamullah Alwee
ID: 41861605
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.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question