Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid column CommandButton
Message
 
 
To
02/01/2020 03:16:50
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01672489
Message ID:
01672508
Views:
67
Antonio,

Thank you (and thanks to Sergey). Correct, your code works. And since the entire change is within the class defined in code, I don't have to change the "framework."

>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?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform