Solved

Alternating row colors different for MsHFlexGrid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now