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

x
?
Solved

Alternating row colors different for MsHFlexGrid

Posted on 2006-07-05
4
Medium Priority
?
245 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
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

Industry Leaders: 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

972 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