Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color Rows in MSFLEXGRID 1

Status
Not open for further replies.

Jomercat

Programmer
Sep 1, 2004
100
US
Hi all,

I hope that somebody can help me with this issue.


I am retrieving records from a database and I would like to highlight in red the rows for a particular department. For example, computers located at a remote location or in a local department.


Any help would be appreciated.

Jose.

 
A quick search turned up the following threads, among others

thread222-753873
thread222-668987
thread222-477340



zemp
 
zemp,

Thanks for your reply!!!

I tried what was suggested on the threads.

I got it to highlight the entire row; however, for some reason it starts to highligh one record before the desired record.

For example.

I have 20 records and need to highlight 6,7,8 and 15,16,17.

It starts to ighlight at 5,6,7 and 14,15,16.


Thanks again.

Jose.
 
It may be because record 0 (the first record) is on row 1 (because the grid's header row is row 0), record 1 is on row 2, and so forth. So if you need to highlight record 6 and you use the recordset index of 5, you will highlight row 5.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hi all,

Thanks for your help!!!

I am still having the same problem. What am I doing wrong?

Here is the code.

For j = 1 To .Rows - 1

For i = 1 To .Cols - 1

Next
Next

If Condition Then
.Row = j - 1
.ColSel = i - 1
.CellBackColor = vbRed

Else
End If

If I use .Row = j without the -1, I get an "Invalid Row Value" message.

Again, thanks for your help.

Jose.
 
It might be because you are not slecting a range of rows. I would think that something like this might work.
Code:
For i = 1 To .Rows - 1
  If yourCondition Then              
    With yourflexigrid
      .FillStyle = flexFillRepeat
      .row = i
      .RowSel =i
      .col = 1
      .ColSel = .cols-1
      .Cellbackcolor = vbRed
      '.CellForeColor = vbWhite
    End With
  end if
Next i
This also avaoids a second loop by selecting a range of columns and setting the .fillstyle property.

I have found that most users have difficulty reading black on a red background, so you may want to consider changing the fore colour as well.


zemp
 
Thanks zemp!!!!

I tried it but it was highlighting more than what I was expecting this time.

This is the complete code.

With Form.MSFlexGrid1

If Not rsComp.EOF Then

rsComp.MoveFirst
.Rows = 1
While Not rsComp.EOF

For i = 1 To .Rows – 1

If Condition Then

.FillStyle = flexFillRepeat
.Row = i
.RowSel = i
.Col = 1
.ColSel = .Cols - 1
.CellBackColor = vbRed

End If
Next i

.Rows = .Rows + 1
.ColWidth(0) = 100
.ColAlignment(2) = 1
.TextMatrix(0, 1) = "Field1"
.TextMatrix(0, 2) = "Field2"
.TextMatrix(0, 3) = "Field3"
.TextMatrix(0, 4) = "Field4"
.ColAlignment(1) = 2
.ColAlignment(2) = 2
.ColAlignment(3) = 2
.ColAlignment(4) = 2
.TextMatrix(.Rows - 1, 1) = rsComp("DB1")
.TextMatrix(.Rows - 1, 2) = "" & rsComp("DB2")
.TextMatrix(.Rows - 1, 3) = "" & rsComp("DB3")
.TextMatrix(.Rows - 1, 4) = "" & rsComp("DB4")

rsComp.MoveNext
Wend
End If
End With


Thanks.

Jose.
 
This is how I might do it...

Code:
    With Form.MSFlexGrid1
    
        'Initialize the grid
        .Rows = 1
        .ColWidth(0) = 100
        .ColAlignment(2) = 1 'This conflicts with the one below
        .TextMatrix(0, 1) = "Field1"
        .TextMatrix(0, 2) = "Field2"
        .TextMatrix(0, 3) = "Field3"
        .TextMatrix(0, 4) = "Field4"
        .ColAlignment(1) = 2
        .ColAlignment(2) = 2 'This conflicts with the one above
        .ColAlignment(3) = 2
        .ColAlignment(4) = 2
        
        If Not rsComp.EOF Then
        
            rsComp.MoveFirst
            
            'Loop through recordset and display the data
            While Not rsComp.EOF
            
                .Rows = .Rows + 1
                
                .TextMatrix(.Rows - 1, 1) = rsComp("DB1")
                .TextMatrix(.Rows - 1, 2) = "" & rsComp("DB2")
                .TextMatrix(.Rows - 1, 3) = "" & rsComp("DB3")
                .TextMatrix(.Rows - 1, 4) = "" & rsComp("DB4")
                              
                If Condition Then 'Hilite new row in red
                
                    .FillStyle = flexFillRepeat
                    .Row = .Rows - 1
                    .RowSel = .Rows - 1
                    .Col = 1
                    .ColSel = .Cols - 1
                    .CellBackColor = vbRed
                                   
                End If
                
                rsComp.MoveNext
            
            Wend
            
        End If
    
    End With
 
jjames,

You deserve a star!!!!!

It worked perfectly!!!!

Thank you so much!!!!

Jose.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top