Solved

Alternating row colors different for MsHFlexGrid

Posted on 2006-07-05
4
240 Views
Last Modified: 2008-02-01
Hi,

I am trying to use the following code for setting the alternating rows in an msHFlexgrid to different color. But its not working. Below is my code. Please help me correct it.

      MSHFlexGrid1.SelectionMode = flexSelectionByRow
            MSHFlexGrid1.AllowBigSelection = True
            Set MSHFlexGrid1.DataSource = rsPatient
           
           
            Dim intCols As Integer
            Dim intCurrRow As Integer
           
            MSHFlexGrid1.Visible = True
            MSHFlexGrid1.Row = 0
            'Fill Columns Headers
            MSHFlexGrid1.ColWidth(0) = 0
           
            On Error GoTo test
            For intCols = 1 To rsPatient.Fields.Count
                MSHFlexGrid1.Col = intCols
                MSHFlexGrid1.Text = rsPatient(intCols).Name
                 MSHFlexGrid1.ColAlignment(intCols) = flexAlignCenterCenter
                MSHFlexGrid1.ColWidth(intCols) = 1200
              Next
test:
            Debug.Print Err.Description
            intCurrRow = 1
            Do While (Not intCurrRow = rsRecCount + 1)
                For intCols = 1 To rsPatient.Fields.Count
                    If intCurrRow Mod 2 = 0 Then
                        MSHFlexGrid1.CellBackColor = &HFFFF00     '&HF5F5F5
                     
                    Else
                         MSHFlexGrid1.CellBackColor = &H8000&
                    End If
                Next
                intCurrRow = intCurrRow + 1
            Loop
       

Thanks
0
Comment
Question by:pmud
[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
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17044486
I think you are forgetting to address the actual cell with the .Row and .Col properties. I've tested with an unbound grid, so the code looks a bit different,  but the relevant lines are indicated
'...
    Debug.Print Err.Description
    intCurrRow = 1
    Do While (Not intCurrRow = MSHFlexGrid1.Rows)
        MSHFlexGrid1.Row = intCurrRow  '<----------------
        For intCols = 1 To MSHFlexGrid1.Cols - 1
            MSHFlexGrid1.Col = intCols      '<--------------
            If intCurrRow Mod 2 = 0 Then
                MSHFlexGrid1.CellBackColor = &HFFFF00     '&HF5F5F5
            Else
                MSHFlexGrid1.CellBackColor = &H8000&
            End If
        Next
        intCurrRow = intCurrRow + 1
    Loop
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17044882
try this.

test:
            Debug.Print Err.Description
            intCurrRow = 1
            Do While (Not intCurrRow = rsRecCount + 1)
                If intCurrRow Mod 2 = 0 Then
                    >>>>MSHFlexGrid1.Cell(flexcpBackColor, intCurrRow, 0, intCurrRow, .Cols - 1) = &HFFFF00
                Else
                    >>>>MSHFlexGrid1.Cell(flexcpBackColor, intCurrRow, 0, intCurrRow, .Cols - 1) = &H8000&
                End If
                intCurrRow = intCurrRow + 1
            Loop
0
 

Author Comment

by:pmud
ID: 17045042
Hi GrahamSkan,

That worked. You are right. I had not refereced the .Cols and .Row property.

Thanks
0
 
LVL 5

Expert Comment

by:lunchbyte
ID: 17045082
But why would you want to loop through each column instead of doing all columns in one row once to save time.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month4 days, 6 hours left to enroll

630 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