Solved

Alternating row colors different for MsHFlexGrid

Posted on 2006-07-05
4
234 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 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now