Further to all everyone said, one way is to do this:
(you mentioned you want to add a checkbox in a grid column with special
code)
1) create your checkbox class
Once the class is created ( in a prg, for instance, with the name
specialchkbx.prg)
procedure specialchkbx
define class mycheck as checkbox
caption = ''
centered = .t.
procedure init
this.value = .f.
endproc
procedure click
(your special code goes here)
endproc
enddefine
endproc
2) you have to insert this checkbox into your grid. To do this, include
a method in the form that you could name set_grid and call it from the
init event of the form thus:
**form init event
thisform.grid1.recordsource = ''
thisform.set_grid()
thisform.grid1.controlsource = 'yourgridcursorname'
** form set_grid method code
set procedure to c:\myproject\classes\specialchkbx.prg additive
with thisform.grid1
with .column3 && I am assuming you want your checkbox in column3
.addobject('check1','mycheck')
.currentcontrol = 'check1'
.removeobject('text1')
.bound = .t.
.sparse = .f.
.readonly = .f.
with .check1
.controlsource = 'yourgridcursorname.logicfield'
.visible = .t.
endwith
endwith
endwith
You have to be careful with a few things:
Your class is made available to your form by the set procedure call
above. Do not omit the word additive. That is important because it will
be added to all other procedures your program may be referencing.
In the grid column, as shown above, you set the sparse property to
false. In this way the checkbox will be shown in all rows, otherwise it
will only be shown in the row the cursor is on and only when the mouse
in on the checkbox itself.
You have to set the current control of the column to the new object, ie
your checkbox, otherwise the default text1 object will be shown.
Finally, you must make the checkbox visible, because it is not visible
by default.
You may have noticed that in the init event of the form I set the
recordsource of the grid to nothing. This is so you can make all
necessary changes to your grid, by means of the call to the set_grid
method, and the grid appearance will not be disrupted. Once you set the
grid recordsource to your cursor, it will work properly.
Hope this helps.
Rafael Copquin
El 28/03/2010 15:44, Carl Lindner escribió:
> Grigore,
>
> Thanks for the nice warm welcome to the big leagues! Over the years I have
> survived of a single application and - for the most part - have always been
> able to use the GUI for development.
>
> My problem started with changing the record source of a grid with an
> embedded checkbox. I just thought it would be easier to deal with the
> concept by using a command button....
>
> Bottom line - my problem was created by me and I now see how it can be
> handled properly with simple code.
>
> Thanks again. Someday I just might have to dig into your comments!
>
> Carl Lindner
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf
> Of Grigore Dolghin
> Sent: Sunday, March 28, 2010 2:19 PM
> To: [email protected]
> Subject: Re: VFP9-SP2 addobject - Method Code
>
> You can't do that. Adding method code in runtime is not supported (it never
> was). You have several workarounds, though.
>
> #1. Create your own button class, enter the code in the Click event of the
> button class then add the button in runtime with AddObject. (You could set
> the properties in design mode so you won't be needed to write the .width=50
> code and such).
> #2. Visual FoxPro allows you to execute code using ExecScript or/and by
> saving it in a prg file, compile it and run it, all in runtime. The only
> problem is how to make the button's click to run your code, and here comes
> BindEvent. Your code should look similar to this (I am writing it directly
> in mail client so there may be bugs, but you'll get the general idea):
>
> *-- First - you'll need a way to run a piece of code by receiving the actual
> code location. I would suggest to add a method in the form:
> MyMethod:
> local lcCode
> lcCode = filetostr(ThisForm.CodeFile)&& now you have the code in memory
> ExecScript(tcCode)
>
>
> With ThisForm
> .AddObject("oCommand", "commandbutton")
> EndWith
> ThisForm.CodeFile = "C:\MyProgram\CodeToBeRunInRuntime.prg"
> *-- Or, alternatively, you can generate the prg on the fly as needed and
> save it to that file name, then assign the filename to the CodeFile
> property.
>
> BindEvent("ThisForm.oCommand", "Click", ThisForm, MyMethod)&& MyMethod will
> try to read the content of the ThisForm.CodeFile property.
> *-----------------------
>
> Experiment and be creative. ;)
> Hope this helps.
> On Sun, Mar 28, 2010 at 9:04 PM, Carl Lindner<[email protected]> wrote:
>
>
>> Thanks, but I cannot make it work
>>
>> I am not sure I understand. The procedure/endproc....
>>
>> I cannot place before thisform.addobject, directly after
>> thisform.addobject,
>> between the with/endwith, or after the endwith. My code is in the init of
>> the form....
>>
>>
>> -----Original Message-----
>> From: [email protected] [mailto:[email protected]] On Behalf
>> Of Aida I. Rivera-Benítez, MSMIS
>> Sent: Sunday, March 28, 2010 1:45 PM
>> To: ProFox Email List
>> Subject: Re: VFP9-SP2 addobject - Method Code
>>
>> PROCEDURE Click
>> ***Your code goes here
>> ENDPROCEDURE
>>
>> The same for Valid.
>>
>> AiR
>> Aida I. Rivera-Benítez, MSMIS
>> AiR Information Systems, Inc.
>> San Juan, Puerto Rico
>>
>> -----------------------------------------------
>> From: "Carl Lindner"<[email protected]>
>> Sent: Sunday, March 28, 2010 1:31 PM
>> To:<[email protected]>
>> Subject: VFP9-SP2 addobject - Method Code
>>
>>
>>> Hey guys, I can use some help.
>>>
>>> thisform.addobject("ocommand","commandbutton")
>>> with thisform.ocommand
>>> .top=60
>>> .height= 50
>>> .width= 50
>>> .visible=.t.
>>> .left=1
>>> endwith
>>>
>>> I run the above in the init code of a form. It creates a clickable
>>> command
>>> button. How would I add code for a valid, or click?
>>>
>>> Thanks.
>>>
>>> Carl Lindner
>>>
>>> [email protected]
>>>
>>
>>
>>
>>
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.