Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to change a command button forecolor in a grid?
Message
De
21/11/2006 22:51:04
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
21/11/2006 17:38:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01171589
Message ID:
01171627
Vues:
11
>hello
>
>how to change a command button forecolor in a grid based on a value in a table that populate the grid?

Something like this:
o=createobject("frmColorButton")
o.show()
read events

define class frmColorButton as form

	add object grd as grid ;
		with columncount=2

	procedure init
		create cursor zz (nColor i)
		insert into zz values (0xffffff)
		insert into zz values (0xffff7f)
		insert into zz values (0xff7fff)
		insert into zz values (0x7fffff)
		insert into zz values (0x7f7fff)
		insert into zz values (0xff7f7f)
		insert into zz values (0x7fff7f)
		with this.grd
			.recordsource="zz"
			.columncount=2
			.column1.controlsource="ncolor"
			with .column2
				scan
					lcName="cmd"+transform(recno(),"9")
					.addobject(lcName, "cmdColor", nColor)
					oCmd=getpem(this.grd.column2, lcName)
					with oCmd
						.visible=.t.
						.caption=lcName
					endwith
				endscan
				.sparse=.f.
				.dynamiccurrentcontrol=["cmd"+TRANSFORM(RECNO(),"9")]
				.currentcontrol="cmd1"
				.removeobject("text1")
			endwith
		endwith

	endproc

	procedure destroy
		clear events
	endproc

enddefine


define class cmdColor as commandbutton
	colorsource=0
	procedure init(nC)
		this.backcolor=nC
	endproc

*!*		procedure refresh
*!*			this.backcolor=zz.nColor
*!*		endproc
enddefine
The cmdColor.Refresh is where I tried to have a single button which would change color, but that didn't work. Note here that I'm having one button for each color - which may not be too elegant if you have too many colors. However, if your colors are few, up to a few dozen (more shades would make them hard to distinguish anyway), you can have a different definition of your .currentControl - maybe something like
.dynamiccurrentcontrol=["cmd"+substr(TRANSFORM(nColor,"@0"),5)]
and have your commandbuttons named in a suitable manner.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform