Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Event Code Programmatically

Status
Not open for further replies.

LouisC4

Programmer
Jul 26, 2003
54
US
Hello,

In my Form I have created a Grid with the following code:

ThisForm.AddObject('Grid1','Grid')
ThisForm.Grid1.Top = 53
ThisForm.Grid1.Left = 20
ThisForm.Grid1.Height = 344
ThisForm.Grid1.Width = 735
ThisForm.Grid1.RecordSource = "GLr1c"
ThisForm.Grid1.Visible = .T.

Now that my grid is working, I would like to programmatically add a click event on [ThisForm.Grid.column2.text1], how can I do this? Is it possible?

Louis
 
LouisC4

faq184-2164

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

Thanks for the reply. I try doing what FQ184-2164 suggested to do but when I ran my code it says that:

"Methods and events cannot contain nested procedures or class defenitions"

What to do?

Louis
 
LouisC4

The problem is, you are trying to add a method to an existing grid, which you cannot do. You have to DEFINE your grid in your main program (somewhere near the bottom is fine) and in the Init of your form add the predefined grid to your form, by using somethign like this.
In your main program:

Code:
DEFINE CLASS grid1 as Grid 
    COLUMNCOUNT = 3
    VISIBLE = .T.
    recordsource = "mycursor"
ENDDEFINE
define class _myheader as header
    procedure click
        wait window TRANSFORM(this.parent.name)+" was clicked" nowait
    endproc
enddefine

In the init of your form.
Code:
WITH this
 .addobject("grid1","grid1")
ENDWITH



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
LouisC4

Sorry the init of the form should read:
Code:
WITH this
 .addobject("grid1","grid1")
ENDWITH
WITH this.grid1
for each oColumn in .columns
    oColumn.addobject("myheader1","_myheader")
endfor
ENDWITH


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top