How do I change the backcolor of every other set of two rows on an MSHFlexGrid?

I have an MSHFlexGrid in a VB6 program that has linescores for baseball games. Every two lines is a complete linescore for a specific game, and I would like to separate the different game linescores by alternating the color of every two rows. How do I make it so that every other two lines is highlighted with a different backcolor? Anyone have a piece of VB6 code that will do this---or know how to explain it to me?
Many thanks.
LVL 4
jazjefAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Your question asks about VB6 but your topics say .Net. I'm hoping you really want VB6 and here's an example. The example only has 10 rows and the colors are hard-coded. If you had a lot more rows than that some other way of choosing the colors would have to be used.
Q-28658527.zip
0
Martin LissOlder than dirtCommented:
To get around having to select a larger number of colors (and make sure that they are light enough to see the text) you might want to choose two colors and swap them every two rows as this does.

Private Sub Form_Load()

    Dim lngRow As Long
    Dim bSwap As Boolean
    With MSHFlexGrid1
        For lngRow = 0 To .Rows - 1 Step 2
            .FillStyle = flexFillRepeat
            
            .Row = lngRow
            .Col = .FixedCols
            
            .RowSel = lngRow
            .ColSel = .Cols - 1
            
            ' RGB colors are from http://www.rapidtables.com/web/color/RGB_Color.htm
            If bSwap Then
                .CellBackColor = RGB(0, 255, 255)
                .Row = lngRow + 1
                .ColSel = .Cols - 1
                .CellBackColor = RGB(0, 255, 255)
            Else
                .CellBackColor = RGB(127, 255, 212)
                .Row = lngRow + 1
                .ColSel = .Cols - 1
                .CellBackColor = RGB(127, 255, 212)
            End If
            bSwap = Not bSwap
        Next
    End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jazjefAuthor Commented:
Thanks MartinLiss .... the copy-paste code works. I had to start at row 1 instead of 0 to Rows - 1 ..... once I did that, the fixed row at the top was excluded and it evens out nicely.

The RGB adjustment method is a nice touch too---I've used that in the past, but forgot how nicely it allows you to find diverse color contrast via subtle adjustment. Thanks for suggesting that as well.
0
jazjefAuthor Commented:
Once again MartinLiss solves my problem. He's like an internet all to himself. Thanks again!!!
0
Martin LissOlder than dirtCommented:
LOL and once again you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.