Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grids
Message
De
30/06/2004 21:16:06
 
 
À
30/06/2004 17:17:11
Jossue Vega
Healthcare Partners
New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Re: Grids
Divers
Thread ID:
00919387
Message ID:
00919463
Vues:
12
This should do what you are looking for. Following is some code I developed that takes advantage of the NewObject() method and DynamicCurrentControl property. I don't know what kind of performance hit you would see if you are displaying a large number of unique records. But it works very well with a small number of records. (I tested with 4 records and saw no delay at all.) I just tested this in VFP9 B1.


1. Create the following CommandButton subclass and save it to a prg file or class module:
DEFINE CLASS cmd AS commandbutton
  Caption = "Command1"
  Name = "cmd"

  PROCEDURE Click
    ExecScript(Evaluate(This.Parent.Parent.RecordSource + ".ccode"))
  ENDPROC
ENDDEFINE
2. Following is a form definition you can use to test with.
**************************************************
*-- Form:         form1 (c:\misc\test.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   06/30/04 10:19:12 PM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 443
	Width = 592
	DoCreate = .T.
	ShowTips = .T.
	Caption = "Form1"
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 1, ;
		Height = 390, ;
		Left = 12, ;
		RecordSource = "tmp", ;
		Top = 12, ;
		Width = 570, ;
		Name = "Grid1", ;
		Column1.ControlSource = "", ;
		Column1.Name = "Column1"


	ADD OBJECT form1.grid1.column1.header1 AS header WITH ;
		Caption = "Header1", ;
		Name = "Header1"


	ADD OBJECT form1.grid1.column1.text1 AS textbox WITH ;
		BorderStyle = 0, ;
		Margin = 0, ;
		ForeColor = RGB(0,0,0), ;
		BackColor = RGB(255,255,255), ;
		Name = "Text1"


	PROCEDURE Load
		Create Cursor tmp (cCaption c(25), cToolTip c(128), cName c(25), cCode m)

		Append Blank
		Replace cCaption With "Hello!", ;
			cToolTip With "Hello and Goodbye", ;
			cName With "Hello", ;
			cCode With 'messagebox("Goodbye. :(")'

		Append Blank
		Replace cCaption With "Try it...", ;
			cToolTip With "Try it... You will like it!", ;
			cName With "TryIt", ;
			cCode With 'messagebox("you will like it!")'

		Append Blank
		Replace cCaption With "VFP 9", ;
			cToolTip With "VFP 9 Beta", ;
			cName With "VFP9", ;
			cCode With 'messagebox("Beta")'

		Append Blank
		Replace cCaption With "Dynamic Controls", ;
			cToolTip With "Dynamic controls rock!", ;
			cName With "Dynamic", ;
			cCode With 'messagebox("dynamic controls rock!")' in tmp
	ENDPROC


	PROCEDURE Form1.Grid1.Column1.Init
		Local lnSelect, ;
			loCmd

		lnSelect = Select(0)

		Select Distinct cName, cCaption, cToolTip ;
		From (This.Parent.RecordSource) ;
		Into Cursor tmp_cur

		Select tmp_cur

                *- You will have to adjust the file location of the .prg file
		Scan
			This.NewObject("cmd" + AllTrim(cName), "cmd", "c:\misc\test.prg")
			loCmd = Evaluate("This.cmd" + AllTrim(cName))
			loCmd.Caption = AllTrim(cCaption)
			loCmd.ToolTipText = AllTrim(cToolTip)
			loCmd.Visible = .T.

		EndScan

		USE In tmp_cur

		This.DynamicCurrentControl = "'cmd' + AllTrim(tmp.cName)"
		This.Sparse = .F.

		Select (This.Parent.RecordSource)

		Go Top

		Select (lnSelect)
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
Hope this helps!

Don



>Hello all;
>Hope everyone is doing well.
>
>I have an issue with a grid, I placed a command button in one of the cells.
>depending on what the users choses I am changing the caption and the tooltip of the command button. When I change them (caption and tooltip) the changes are applied to all of the command buttons in all of the cells. What am i doing wrong?
>
>thank you in advance for any help or suggestions.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform