7 |
The LA Fox Developer Newsletter
|
April 1997
|
VFP 5.0 Grids
(Con't from page 6)
Beyond the basics
Suppose you want users to be able to see data in your grid but not change anything. Sounds easy, just set the grid’s enabled
property to False. Yeah, this keeps users from making changes but it also disables the scroll bars so they can’t move around. A better way is to leave the grid enabled and mark each column’s ReadOnly property False (shown in example code below).
Users can’t change or enter data but the scroll bars are functional allowing everything to be browsed.
A basic rule to remember is that a property of a control inside of
a column is overridden by the same property of the Column. Our
ReadOnly example above works because of this. It also applies
to colors.
Displaying colors in grids usually takes a little practice to get everything right. Lets check out the following code from the Refresh event of a sample grid:
_screen.lockscreen
=
.T. this.backcolor
=
EVAL(”RGB(”+SUBSTR(RGBSCHEME(15,1),AT(”,”,RGBSCHEME(15,1),3)+1))
DO CASE
CASE this.enabled AND !this.readonly
this.SetAII(”DynamicBackColor”,
IIF(this.ActiveRowRECNOO,RGB(225,O,O),RGB(255,255,255)), IIF(this.ActiveRowRECNOO,RGB(225,O,O),
EVAL(”RGB(”+SUBSTR(RGBSCHEME(15,1),;
AT(”,”,RGBSCHEME(15,1),3)+1))))’,;
CASE !this.enabled AND !this.readonly
this.SetAIl(”DynamicBackColor”,
AT(”,”,RGBSCHEME(15,1),3)+1))’, “Column’
wait window “Not Enabled and Not Read Only”
CASE this.readonly
this.SetAll(”DynamicBackColor”,
‘RGB(192,192,1 92)’,; “Column”)
wait window “Read Only”
ENDCASE
this.SetAll(”Enabled”, this.Enabled, “Column”) this.SetAll(”Enabled”, this.Enabled, “Textbox”) this.ReadOnly
=
this.enabled
IF !this.Enabled
this.Enabled
=
.T.
ENDIF
DO CASE
CASE thisform.mvaCommandGroup2.value
=
1
thisform.mvagridl Column1 .dynamicbackcolor
=
‘IIF(this.ActiveRowRECNOO,RGB(225,O,O),
EVAL(”RGB(”+SUBSTR(RGBSCHEME(15,1),;
AT(”,”,RGBSCHEME(15,I),3)+1)))’
CASE thlsform.mvaCommandGroup2.value
=
2
thisform.mvagridl .Columnl .dynamicbackcolor
=
‘EVAL(”RGB(”+SUBSTR(RGBSCHEME(15,I),;
AT(”,”,RGBSCHEME(15,I),3)+1))’
CASE thisform.mvaCommandGroup2.value
=
3
|
thisform.mvagridl.Columnl.dynamicbackcolor
=
“RGB(255,255,128)”
CASE thisform.mvaCommandGroup2.value
=
4
*! nothing
ENDCASE
this.column4.textl .refresh()
screen.lockscreen
=
.F.
We start out by setting the grid backcolor property
to be the
same as the Windows color property. Next we check the grid’s
enabled and readonly properties and set colors as appropriate. Individual rows are set using each column’s dynamicbackcolor property.
In the case of enabled and not readonly, we create a ledger bar effect of alternating rows of white and Window color while the active row has a background color of red. For the case of not enabled and not readonly, all rows are set to the current Window color, and for the case readonly, all rows are set to light grey.
After some housekeeping of the enabled and readonly properties of the controls, we respond to some command button choices. The whole thing is wrapped with lockscreen to improve visual performance.
Colors can be carried further to individual cells. This example is taken from another grid’s refresh event:
this.Column5.DynamicBackColor
=
‘IIF(v_myview.value
=
“I”,RGB(O,255,O), llF(v_myview.value
=
“2”,RGB(O,255,255), IIF(v_myview.value
=
“3”,RGB(O,O,255), IIF(v_myview.value
=
“4”,RGB(255,O,255), IIF(v_myview.value
=
“5”,RGB(255,O,O), RGB(255,255,O))))))’
Six different background colors are possible here. There are two tricks. The first is that whatever you do must be an inline statement. If I would have used a case statement, the whole column would have a backcolor of the current control’s value. The second trick is how far you can nest IIF statements
-
this seems to be the maximum level.
Out and About
(Con't from page 2)
San
Diego DevCon Announced. The 1997 Visual FoxPro DevCon will be held in San Diego. Send your name, company, mailing address, telephone, fax and email info to
FoxProDevCon@advisor.com
to get on the mailing list, Include topics you would like to see covered at the ‘97 DevCon. Also, check out this page at advisor.com periodically for more details as the sessions and speakers are finalized. And we’ll keep you
as informed as possible, right here, as details develop.
|
Page 7
|
7 |