Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > MSFlexgrid - color rows


Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2002, 09:25 AM
Carrie Carrie is offline
Contributor
 
Join Date: Nov 2002
Posts: 485
Default MSFlexgrid - color rows


I am displaying a query from my database in a Flexgrid. Depending on the contents of one field displayed - I would like the row colour to change. For example if the first column contains an R, I need the row to be red (either text or background) and if it contains anything else to be standard (i e white background with black text)

There must be an easy way to do this?
Reply With Quote
  #2  
Old 12-08-2002, 09:31 AM
Anis's Avatar
Anis Anis is offline
| Coder XXX |

Retired Leader
 
Join Date: Jun 2001
Location: Kuala Lumpur, Malaysia.
Posts: 3,018
Default

You can use the .cellbackcolor property.
__________________
Regards,
Muhammad Anis Ur Rehman

Miles to go Before I Sleep.

http://www.projekcarpet.com/anis.html
Reply With Quote
  #3  
Old 12-08-2002, 09:55 PM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

As Anis said, you can change the property, but you will have to
code it. There isn't an easy way to automate it. But, the flexgrid
TextMatrix property will make it pretty easy to do this in a loop.
In order to use the cellbackcolor, you will have to first set the row
and col property to point to the cell you want to change.
__________________
Posting Guidelines
Reply With Quote
  #4  
Old 12-09-2002, 01:35 AM
Carrie Carrie is offline
Contributor
 
Join Date: Nov 2002
Posts: 485
Default

Thanx guys - I now have it sussed.
Reply With Quote
  #5  
Old 03-27-2003, 04:24 PM
jemlay jemlay is offline
Newcomer
 
Join Date: Mar 2003
Posts: 12
Default

I need to do the same thing but I'm not understanding how to use TextMatrix for the cell color. Also is there a way to change the font color instead?

My Code:
Do
lRow = myFG.Rows
myFG.Rows = myFG.Rows + 1
myFG.TextMatrix(lRow, 0) = Mid(myRS.Fields(17).Value, 2, 10)
myFG.TextMatrix(lRow, 1) = myRS.Fields(3).Value
If myRS.Fields(8).Value = "1" Then
myFG.TextMatrix(lRow, 2) = "NOT SENT"
ElseIf myRS.Fields(8).Value = "2" Then
myFG.TextMatrix(lRow, 2) = "WAITING"
ElseIf myRS.Fields(8).Value = "7" Then
myFG.TextMatrix(lRow, 2) = "YES"
ElseIf myRS.Fields(8).Value = "13" Then
myFG.TextMatrix(lRow, 2) = "WAITING"
ElseIf myRS.Fields(8).Value = "14" Then
myFG.TextMatrix(lRow, 2) = "REJECTED"
Else
myFG.TextMatrix(lRow, 2) = "UNKNOWN"
End If
myFG.Row = lRow
myFG.Col = 2
myFG.CellAlignment = 4
myRS.MoveNext
Loop Until myRS.EOF


I'm wanting only the rejected field to change color.

Thanks
Reply With Quote
  #6  
Old 03-27-2003, 05:15 PM
jemlay jemlay is offline
Newcomer
 
Join Date: Mar 2003
Posts: 12
Default

Ok, so I figured out how to do it.

Do
lRow = myFG.Rows
myFG.Rows = myFG.Rows + 1
myFG.Row = lRow
myFG.Col = 2
myFG.CellAlignment = 4
myFG.CellBackColor = RGB(255, 255, 255)
myFG.TextMatrix(lRow, 0) = Mid(myRS.Fields(17).Value, 2, 10)
myFG.TextMatrix(lRow, 1) = myRS.Fields(3).Value
If myRS.Fields(8).Value = "1" Then
myFG.TextMatrix(lRow, 2) = "NOT SENT"
ElseIf myRS.Fields(8).Value = "2" Then
myFG.TextMatrix(lRow, 2) = "WAITING"
ElseIf myRS.Fields(8).Value = "7" Then
myFG.TextMatrix(lRow, 2) = "YES"
ElseIf myRS.Fields(8).Value = "13" Then
myFG.TextMatrix(lRow, 2) = "WAITING"
ElseIf myRS.Fields(8).Value = "14" Then
myFG.CellBackColor = RGB(255, 0, 0)
myFG.TextMatrix(lRow, 2) = "REJECTED"
Else
myFG.TextMatrix(lRow, 2) = "UNKNOWN"
End If
myRS.MoveNext
Loop Until myRS.EOF


Only thats not going to work as I allow the user to resort the grid. I'm assuming I have two options. In my sort Module I either need to remember these rows (ugh). Or is there a way to go through the grid and change the TEXT color of the word Rejected when found?

Thanks,
Justin
Reply With Quote
  #7  
Old 03-27-2003, 05:36 PM
Thinker Thinker is offline
Iron-Fisted Programmer

Retired Moderator
* Guru *
 
Join Date: Jul 2001
Location: Fayetteville Arkansas USA
Posts: 18,127
Default

In the code above you are comparing for numbers in the recordset field
values. Instead of doing that you would compare to the TextMatrix()
value. So instead of looping through all the rows in the recordset, you
loop through all the rows in the flexgrid.
__________________
Posting Guidelines
Reply With Quote
  #8  
Old 03-27-2003, 06:19 PM
jemlay jemlay is offline
Newcomer
 
Join Date: Mar 2003
Posts: 12
Default

Got it.

Public Sub MSFlexGrid_AlternateRowColors()

Dim lRow As Long, lCol As Long
Dim lOrgRow As Long, lOrgCol As Long
Dim lColor As Long

MSFlexGrid1.Redraw = False

lOrgRow = MSFlexGrid1.Row
lOrgCol = MSFlexGrid1.Col

For lRow = MSFlexGrid1.FixedRows To MSFlexGrid1.Rows - 1
MSFlexGrid1.Row = lRow

If MSFlexGrid1.TextMatrix(lRow, 2) = "REJECTED" Or MSFlexGrid1.TextMatrix(lRow, 2) = "NOT SENT" Then
lColor = RGB(255, 0, 0)
Else
lColor = RGB(255, 255, 255)
End If

For lCol = MSFlexGrid1.FixedCols To MSFlexGrid1.Cols - 1
MSFlexGrid1.Col = lCol
MSFlexGrid1.CellBackColor = lColor
Next lCol
Next lRow

MSFlexGrid1.Row = lOrgRow
MSFlexGrid1.Col = lOrgCol
MSFlexGrid1.Redraw = True

End Sub


Then run this code after each time I sort. Thanks again!
Reply With Quote
  #9  
Old 03-31-2003, 02:59 PM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,040
Default

Reply With Quote
  #10  
Old 08-28-2003, 05:36 AM
nsmoller nsmoller is offline
Junior Contributor
 
Join Date: Aug 2003
Posts: 286
Default

that was awesome help, thanks alot...

i used cellforecolor=vbred to say when a quantity drops below an alert quantity
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->