Results 1 to 7 of 7

Thread: [RESOLVED] Color FlexGrid Based on Data in Cell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Resolved [RESOLVED] Color FlexGrid Based on Data in Cell

    I have a column and I want to paint it certain colors depending on the text.

    I found some code and tried to recycle it but that didnt work... Here is the code
    VB Code:
    1. Dim lrow, lcol As Integer
    2.     Dim lcolor As String
    3.    
    4.         With MSFlexGrid1
    5.                 For lrow = .FixedRows To .Rows
    6.                     .Row = lrow
    7.                     If UCase(.TextMatrix(lrow, 1)) = "BREAK" Then
    8.                         lcolor = vbGreen
    9.                         For lcol = 0 To 1
    10.                             .Col = lcol
    11.                             .CellBackColor = lcolor
    12.                         Next lcol
    13.                     ElseIf .CellBackColor <> vbGreen Then
    14.                         lcolor = vbRed
    15.                     End If
    16.                 Next lrow
    17.         End With

    It goes into an infinity loop and crashes the IDE.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Color FlexGrid Based on Data in Cell

    Put some DEBUG.PRINT statements above the WITH and in the WITH.

    My guess is that, since when you change .COL or .ROW, you trigger FLEXGRID events like ROWCHANGE and COLCHANGE that you are getting yourself in trouble with that.

    Maybe .ENABLED=FALSE will help?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Color FlexGrid Based on Data in Cell

    That code alone will not cause an infinite loop but will cause an "Invalid Row" error. The For Loop should be

    For lrow = .FixedRows To .Rows -1

    Do you have code in any of the FlexGrid events, such as EnterCell or RowColChange?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: Color FlexGrid Based on Data in Cell

    Right Now that code is in the LeaveCell attribute, I wish to update every time a user changes something.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Color FlexGrid Based on Data in Cell

    Then I believe that if you put a debug.print at the top of the LEAVE CELL event you will see if get triggered repeatedly, as you change .COL values.

    I'm guessing though...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: Color FlexGrid Based on Data in Cell

    Here is an updated working version of the script. I used a Bool Operator to keep it from going haywire.

    VB Code:
    1. Private Function ColorRows(pLookFor As String, pLookRow As Integer, ByVal pColor As String)
    2.     Dim lrow, lcol As Integer
    3.         With MSFlexGrid1
    4.             FlexGridDone = False
    5.                 .Redraw = False
    6.                 For lrow = .FixedRows To .Rows - 1
    7.                     .Row = lrow
    8.                     If UCase(.TextMatrix(lrow, pLookRow)) = pLookFor Then
    9.                         For lcol = 1 To (TotalCols - 1)
    10.                             .Col = lcol
    11.                             .CellBackColor = pColor
    12.                         Next lcol
    13.                     End If
    14.                 Next lrow
    15.                 .Redraw = True
    16.         End With
    17.         FlexGridDone = True
    18. End Function

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: [RESOLVED] Color FlexGrid Based on Data in Cell

    Similar to what we do - but we still use the .ENABLED property of the flex grid and then check that instead.

    Same thing really - just need a way to not "re-iterate" when doing something like that from the LEAVECELL event.

    The FLEXGRID drives me crazy because of stuff like that!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width