Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Buttons in a grid change caption
Message
 
To
06/05/2013 12:30:02
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01572779
Message ID:
01572798
Views:
66
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
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform