Solved

Alternating row colors different for MsHFlexGrid

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

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 42
clicking a shape in a frame array vb6 3 48
Problem to With line 4 74
Automatic Email Reminder 4 71
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

740 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