Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid column CommandButton
Message
De
02/01/2020 03:16:50
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01672489
Message ID:
01672506
Vues:
64
Dmitry,

As Sergey told you, using a container would give you more control over the size of the command button.

Normally that wouldn't add to much to your current class, but of course I'm saying this without full knowledge of your environment.

This is the revision of the MyCommand class of the demo to accommodate the button inside a container. The rest remains as it was before.
DEFINE CLASS MyCommand AS Container

	BackStyle = 0
	BorderWidth = 0

	ADD OBJECT MyButton AS CommandButton WITH Caption = "Click me!"

	PROCEDURE MyButton.Click
		MESSAGEBOX(TEXTMERGE("Ouch! <<DemoCursor.Person>>!"))
	ENDPROC

ENDDEFINE
>Antonio,
>Yes, your code works without an error. I will double check what I am doing.
>But, having said it, if I comment the line
>
>.CurrentControl = "MyCommand"
>
>the code works just as well. I probably didn't explain my issue correctly. I wanted the button to be narrower than the column width. And no matter what I do (specify width), the button extends to the width of the column.
>So, my question is, how do you set the width of the button to be narrower than the width of the column? Or, is it possible?
>Thank you.
>
>>Dmitry, you'll have to double check. It should be really straightforward.
>>
>>A quick demo just to select and execute selection:
>>
>>
>>CREATE CURSOR DemoCursor (Id Int AUTOINC, Person Varchar(100))
>>INSERT INTO DemoCursor (Person) VALUES ("Joseph")
>>INSERT INTO DemoCursor (Person) VALUES ("Mary")
>>GO TOP
>>
>>LOCAL DemoForm AS CommandInGrid
>>
>>m.DemoForm = CREATEOBJECT("CommandInGrid")
>>m.DemoForm.Show(1)
>>
>>DEFINE CLASS CommandInGrid AS Form
>>
>>	ADD OBJECT MyGrid AS Grid
>>
>>	PROCEDURE MyGrid.Init
>>
>>		This.ColumnCount = 2
>>
>>		WITH This.Columns(2)
>>
>>			.Sparse = .F.
>>
>>			.RemoveObject("Text1")
>>			.AddObject("MyCommand", "MyCommand")
>>			.MyCommand.Visible = .T.
>>			.CurrentControl = "MyCommand"
>>
>>		ENDWITH
>>
>>	ENDPROC
>>
>>ENDDEFINE
>>
>>DEFINE CLASS MyCommand AS CommandButton
>>
>>	Caption = "Click me!"
>>
>>	PROCEDURE Click
>>		MESSAGEBOX(TEXTMERGE("Ouch! <<DemoCursor.Person>>!"))
>>	ENDPROC
>>
>>ENDDEFINE
>>
>>
>>>Antonio,
>>>
>>>Thank you for your suggestion. If I follow it, I still get the error:
>>>"CurrentControl : Expression evaluated to an illegal value"
>>>
>>>>Dmitry,
>>>>
>>>>You set the .CurrentControl, which is a string property, to the name you gave to the control (that would be "MyCommand").
>>>>
>>>>Since you're adding the object, you also must set its visibility to .T. for it to be shown and operational.
>>>>
>>>>That is:
>>>>
>>>>
>>>>with toGrid.columns(nColumn)
>>>>		.RemoveObject( "Text1" )	
>>>>		.AddObject( "MyCommand", "MyCommand" )
>>>>		.MyCommand.Visible = .T.
>>>>		.CurrentControl = "MyCommand"
>>>>endwith
>>>>
>>>>
>>>>>I still don't get it how to set the value of the CurrentControl in code.
>>>>>
>>>>>Here is the segment of my code that programatically changes the Text1 control to a button:
>>>>>
>>>>>with toGrid.columns(nColumn)
>>>>>		.RemoveObject( "Text1" )	
>>>>>		.AddObject( "MyCommand", "MyCommand" )	
>>>>>
>>>>>               **!! ERROR!
>>>>>		.CurrentControl = "cmdButton" && or "CommandButton" or "MyCommand"	
>>>>>
>>>>>
>>>>>What is wrong with the above code?
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform