Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Buttons in a grid change caption
Message
De
07/05/2013 11:44:31
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01572779
Message ID:
01572888
Vues:
159
Thanks all for your help. I was able to you Hugo's example to make this work for the most part. The only problem that I have is when sometimes the captions get mixed up when clicking on the buttons in reverse order. I don't think this will be a problem for me since this is a pick list and the screen changes as soon as the button is selected.


>Hi James,
>
>What you can do is use one of dynamic properties of the grid columns to update the caption of the button, VFP will be smart enough to update the appropriate button.
>
>The following would be an example, but because I used the class viewer to translate the form into code there is lots of uglyness on it, but it works... You will not need the bindevent to the click of the button, you can do it directly in the click of the button on the designer
>
>
>loForm			= createobject('myForm')
>loForm.show(1)
>
>define class myForm as form
>
>
>	datasession				= 2
>	top					= 0
>	left					= 0
>	height					= 357
>	width					= 615
>	docreate				= .t.
>	caption					= "Form"
>	name					= "myForm"
>
>
>	add object myGrid as grid with ;
>		columncount				= 2, ;
>		anchor					= 15, ;
>		height					= 324, ;
>		left					= 12, ;
>		panel					= 1, ;
>		recordsource				= "C_Test", ;
>		rowheight				= 25, ;
>		top					= 24, ;
>		width					= 570, ;
>		themes					= .f., ;
>		name					= "myGrid"
>
>	function setGridButtonCaption()
>		with thisform.myGrid.column2.myCommand
>			.caption				= alltrim(c_test.somevalue)
>		endwith
>		return .f.
>	endfunc
>
>	procedure GridButtonClicked()
>		messagebox('button ' + transform(c_test.pk) + ' clicked! (' + alltrim(c_test.somevalue) + ')')
>	endproc
>
>	procedure init
>		with thisform.myGrid.Column1
>			.controlsource			= "C_Test.pk"
>			.name				= "Column1"
>		endwith
>
>		with thisform.myGrid.column2
>			.controlsource			= "c_test.somevalue"
>			.width					= 100
>			.sparse					= .f.
>			.dynamicfontstrikethru	= "thisform.setGridButtonCaption()"
>			.name					= "Column2"
>		endwith
>
>		with thisform.myGrid.Column1.header1 as header
>			.alignment				= 2
>			.caption				= "PK"
>			.name					= "Header1"
>		endwith
>
>		with thisform.myGrid.Column1.text1 as textbox
>			.borderstyle				= 0
>			.margin					= 0
>			.forecolor				= rgb(0,0,0)
>			.backcolor				= rgb(255,255,255)
>			.name					= "Text1"
>		endwith
>
>		with thisform.myGrid.column2.header1 as header
>			.caption				= "Your Command"
>			.name					= "Header1"
>		endwith
>
>		thisform.myGrid.column2.addobject('myCommand', 'commandbutton')
>		thisform.myGrid.column2.removeobject('text1')
>
>		with thisform.myGrid.column2.myCommand as commandbutton
>			.caption					= ''
>			.enabled					= .t.
>			.visible					= .t.
>		endwith
>
>		thisform.myGrid.column2.CurrentControl	= 'myCommand'
>		
>		BindEvent(thisform.myGrid.Column2.myCommand, 'Click', thisform, 'GridButtonClicked')
>	endproc
>
>	procedure load()
>		create cursor C_Values (value C(15))
>		create cursor c_test (pk int autoinc, somevalue C(10))
>
>		insert into C_Values (value) values ('Possible')
>		insert into C_Values (value) values ('Impossible')
>		insert into C_Values (value) values ('Probable')
>		insert into C_Values (value) values ('Improbable')
>		insert into C_Values (value) values ('Random')
>
>		rand(-1)
>		do while reccount('C_Test') < 1000
>			go (rand() * reccount('C_Values') + 1) in C_Values
>			insert into c_test (somevalue) values (C_Values.value)
>		enddo
>		go top in c_test
>	endproc
>
>enddefine
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform