You can absolutely use RGB() instead of 0x... Actually you can use anything there that returns a numeric value in the range 0...16777215.
I wast lazy to write rgb(255,0,0) and use 0xFF instead (to be clear 0x0000FF). All of these return the same value:
? rgb(255,255,0)
? 0x0000FF
? 255
In RGB() function colors are RGB( red, green, blue ). Each of the red,green,blue components could be in 0..255 range (which in hex notation 0x0...0xFF). With hex type writing it's however:
0xBlueGreenRed
rgb(0,0,0) = 0x000000 = 0
rgb(255,255,255) = 0xFFFFFF = 16777215
rgb(255,255,0) = 0x00FFFF = 65535
rgb(128,128,128) = 0x808080 = 8421504
and so on.
A more flexible version of the code (I suggest this one in fact, as it's easier to modify per column as you wish).
Public oForm
oForm = Createobject("myForm")
oForm.Show()
Define Class myForm As Form
DataSession = 2
Height = 400
Width = 600
Add Object myGrid As Grid With ;
Height = 400, Width = 600, RecordSource="employee"
Procedure Load
Use employee
Endproc
Procedure Init
For Each oColumn In This.myGrid.Columns
oColumn.DynamicBackColor = "thisform.MyColColor(["+oColumn.ControlSource+"])"
Endfor
Endproc
Procedure myColColor
Lparameters tcControlSource
Local luValue, lnColor
lnColor = 0xFFFFFF
If Type(m.tcControlSource) = 'G'
Return m.lnColor
Endif
luValue = Evaluate(m.tcControlSource)
Do Case
Case Lower(m.tcControlSource) = "employee.title"
If Lower(m.luValue) = "sales manager"
lnColor = Rgb(255,255,0)
Endif
Case Lower(m.tcControlSource) = "employee.birth_date"
If Year(luValue) % 2 = 0
lnColor = Rgb(0,255,255)
Endif
Endcase
Return m.lnColor
Endproc
Enddefine
With this version:
Procedure Init
For Each oColumn In This.myGrid.Columns
oColumn.DynamicBackColor = "thisform.MyColColor(["+oColumn.ControlSource+"])"
Endfor
Endproc
Sets each column's dynamicbackcolor relevant to its contents (controlsource name is sent to method). If you check columns' properties at runtime it shows as:
Column1.ControlSource = ...
...
ColumnX.ControlSource = "employee.title"
ColumnX.DynamicBackColor = "thisform.myColColor([employee.title])"
ColumnY.ControlSource = "employee.birth_date"
ColumnY.DynamicBackColor = "thisform.myColColor([employee.birth_date])"
MyColor method then checks passed controlsource. If it's a general field returns default color white at top. Otherwise checks if it's 'title' or 'birth_date' column and returns choosen colors for the current row value (ie: if born on an even year Cyan). While it's not too late I suggest you code as this version. It's much more flexible for later modifications if need be.
Cetin
>Cetin
>
>No it was my fault - gimmecolor was ok but in the form init I had it as GimmeColor also I was using the wrong database - so it's working
>
>Cetin - you have a gift for providing a solution in simple terms - thank you
>
>Just 1 more question - Return 0x0000FF defines a certain color - how do I find these values from RGB values as I need to convert existing RGB to these values - or can I use RGB?
>
>Thanks very much
>
>Colin
>
>>Colin,
>>My guess is that it's about English:) Could you be that I wrote it as GimmeColor and you created your method as GimmeColour?
>>
>>
>>Public oForm
>>oForm = Createobject('myForm')
>>oForm.Show
>>
>>Define Class myForm As Form
>> DataSession=2
>> Height = 450
>>
>> Add Object myGrid As Grid With Height = 450
>>
>> Procedure Load
>> Create Cursor manifest (Status c(1), myField i)
>> For ix=1 To 20
>> Insert Into manifest Values (Chr(Asc('A')+Int(Rand()*5)),m.ix)
>> Endfor
>> Locate
>> Endproc
>>
>> Procedure GimmeColour
>> Lparameters tcValue
>> Do Case
>> Case m.tcValue = 'A'
>> Return 0xFF0000
>> Case m.tcValue = 'B'
>> Return 0x00FF00
>> Case m.tcValue = 'C'
>> Return 0x0000FF
>> Otherwise
>> Return 0xFFFFFF
>> Endcase
>> Endproc
>>
>> Procedure Init
>> This.myGrid.SetAll('DynamicBackColor','(thisform.GimmeColour(manifest.status))')
>> Endproc
>>Enddefine
>>
Cetin
>>
>>>Cetin
>>>
>>>I have put the first line ie
>>>
>>>thisform.grid1.Setall('DynamicBackColor','(thisform.GimmeColor(manifest.status))') in form init
>>>
>>>The rest of your code I have out in a new form method called GimmeColor
>>>
>>>I get invalid dynamicbackcolour expression
>>>
>>>What have i done wrong?
>>>
>>>Colin
>>>
>>>>>I have tried multiple colors in a grid before but so far have not cracked it even with help from the experts
>>>>>
>>>>>Let me try again
>>>>>
>>>>>I have a table called manifest which has a field called status
>>>>>
>>>>>If status is A I want to color the row blue
>>>>>If B the row will be red
>>>>>If C the row will be green
>>>>>
>>>>>How do I do it?
>>>>>
>>>>>A real layman's explanation would be greatly appreciated
>>>>>
>>>>>Thanks
>>>>>
>>>>>Colin Northway
>>>>
>>>>
>>>>* Anywhere you want to set dynamic coloring - ie: form init
>>>>thisform.myGrid.Setall('DynamicBackColor','(thisform.GimmeColor(manifest.status))')
>>>>
>>>>*Form custom GimmeColor
>>>>lparameters tcValue
>>>>do case
>>>>case m.tcValue = 'A'
>>>> return 0xFF0000
>>>>case m.tcValue = 'B'
>>>> return 0x00FF00
>>>>case m.tcValue = 'C'
>>>> return 0x0000FF
>>>>otherwise
>>>> return 0xFFFFFF
>>>>endcase
Cetin