Clicking on a button within a DataGrid Form

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Clicking on a button within a DataGrid Form

Post by cusingerBUSCw5N » Tue Sep 11, 2012 1:47 am

I have succeeded in making it so that if you click anywhere EXCEPT on the button...it will execute my code. I would like it to execute when you click on the button within the DataGrid and no where else.

First, I tried putting instructions in the button's object script. When I put answer "here" on the button's object script (within the Datagrid form) - it doesn't respond at all. So, I decided that everything needed to go into Row Behavior....

I have a datagrid form.
My button "link_address" is in the datagrid form.

I currently have code in the Row Behavior of the form:

on mouseUp pTheButton
if (pTheButton is 1) then
put the dgIndex of me into tTheIndex
put getDataOfIndex(tTheIndex, "label 1") into tgo
launch url(tgo)
end if
end mouseUp

...which works nicely for every part of my form except the button.


If I put in

if (the short name of the target is "link_address") then
put the dgIndex of me into tTheIndex
put getDataOfIndex(tTheIndex, "label 1") into tgo
launch url(tgo)
end if


then nothing works -because it doesn't recognize the button. putting in target is "col 1" (the name of the column which loads into my link_address button)
- no change.

Thanks

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clicking on a button within a DataGrid Form

Post by Klaus » Tue Sep 11, 2012 4:11 pm

Hi

can't you attach the working "mouseup" script directly to the appropriate button in the TEMPLATE GROUP of the datagrid?
That's what I would do. :D


Best

Klaus

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Clicking on a button within a DataGrid Form

Post by cusingerBUSCw5N » Tue Sep 11, 2012 8:23 pm

I think that's what I was doing...but the button won't even accept answer "hello" when you test it.

To be clear - when I tested the answer "hello" capability, I clicked on the datagrid...went into row behavior...then went up to the top controls to do edit group...then clicked on the button...and then went to object script and entered answer "hello"... When I tested it - nothing...

So it's not recognizing the button within the template (the DataGrid form template)

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clicking on a button within a DataGrid Form

Post by Klaus » Wed Sep 12, 2012 10:43 am

Hi,

sorry, completely puzzled, works fine here...!?


Best

Klaus

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Clicking on a button within a DataGrid Form

Post by cusingerBUSCw5N » Wed Sep 12, 2012 8:12 pm

Mine simply doesn't work. Here's what I am doing:

Click on the datagrid, then click on rowtemplate to get this (see image):
Image

I go to the top and edit group. Then I click on my button, and go to object script and type in answer "hi" (see image):
Image

Then I save it and click on the button and get nothing.

FYI, here is the code for the datagrid's row behavior - I can't see what it's doing to cause this problem......

Code: Select all

on FillInData pDataArray
    
   set the text of field "Col3" of me to pDataArray["label 1"]
   set the text of field "label" of me to pDataArray["label 2"]
   set the text of field "govlevel" of me to pDataArray["label 3"]
   set the text of field "id_desc" of me to pDataArray["label 4"]
   set the text of field "topic_image" of me to pDataArray["label 5"]

   set the filename of image "image_resource" of me to pDataArray["label 5"]

end FillInData

on LayoutControl pControlRect
    local theFieldRect
    
    -- This message is sent when you should layout your template's controls.
    -- This is where you resize the 'Background' graphic, resize fields and 
    -- position objects.
    -- For fixed height data grid forms you can use items 1 through 4 of pControlRect as
    -- boundaries for laying out your controls.
    -- For variable height data grid forms you can use items 1 through 3 of pControlRect as
    -- boundaries, expanding the height of your control as needed.
        
    -- Example:
    set the right of image "image_resource" of me to item 3 of pControlRect - 5
    set the top of image "image_resource" of me to item 2 of pControlRect + 35
    put the left of image "image_resource" of me into theLeft
    put the rect of image "image_resource" of me into theRectImage
    set the rect of image "image_resource" of me to theRectImage
    
    set the left of field "label" of me to item 1 of pControlRect + 5
    set the top of field "label" of me to item 2 of pControlRect + 5
    put the rect of field "label" of me into theRect0

    set the rect of field "label" of me to theRect0
        
    set the left of field "id_desc" of me to item 1 of pControlRect + 5
 
set the top  of field "id_desc" of me to the top of field "label" of me + the formattedheight of field "label" of me + 5
put the rect of field "id_desc" of me into theRect1
put theLeft - 5 into item 3 of theRect1
set the rect of field "id_desc" of me to theRect1   

set the top of button "link_address" of me to the top of field "id_desc" of me + the formattedheight of field "id_desc" of me + 5
put the rect of button "link_address" of me into theRect2
set the left of button "link_address" of me to item 1 of pControlRect + 5

put item 4 of theRectImage + 20 into tone
put item 4 of pControlRect into ttwo
put max(tone,ttwo) into tuse

put tuse into item 4 of pControlRect                                                                                                                                                                                                                                
    set the rect of graphic "Background" of me to pControlRect
end LayoutControl

on ResetData
    -- Sent when data is being emptied because the control is no longer being used to display data
    set the text of field "Label" of me to empty
end ResetData

on PreFillInData
    -- Sent right before new data is going to replace existing data in the control
end PreFillInData

setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your custom template has
    -- changed. By default the "Background" graphic will be highlighted for you. 
    -- You only add script here if you want to further customize the highlight.
    
    -- Example:
    if pBoolean then
        set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
    else
        set the foregroundColor of me to empty
    end if
end dgHilite

getprop dgDataControl
    -- Required by library so that it can locate your control.
    return the long ID of me
end dgDataControl

on mouseUp pTheButton

end mouseUp
If I put this code in the datagrid's row behavior script -

Code: Select all

on mouseUp pTheButton
     if (pTheButton is 1) then
put the dgIndex of me into tTheIndex
put getDataOfIndex(tTheIndex, "label 1") into tgo

launch url(tgo)
end if
end mouseUp
I can get it to work if you click on the datagrid's image or ONE of the fields (called label). If you click on the other field or my button, it won't work. I can't see anything special with the other field..or my button...that would cause it not to fire....

I checked the button properties and they are NOT disabled.

Maybe I need to start from scratch. Is there sample code where a button inside a datagrid form works? This functionality is key to my app...

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Clicking on a button within a DataGrid Form

Post by cusingerBUSCw5N » Wed Sep 12, 2012 8:23 pm

New information - the problem is probably not with my button inside the form.

I click on row template and BEFORE I edit group, in the regular run mode, I click on my button and it works.

So...why in regular run mode, doesn't it work in real app?

All I can think of is something about my datagrid form isn't complete - so it's stopping somewhere before it processes clicking on my button.

On checking, there is an error " revdberr, invalid connection ID - and it seems to be stopping at

on databaseDisconnect
revCloseDatabase the cDatabaseID of me
end databaseDisconnect

Not sure why or how this is a problem, since I've been pulling data from a database on several other cards.....why it's tripping here ....any ideas on how to fix it?

cusingerBUSCw5N
Posts: 339
Joined: Wed Jul 11, 2012 9:24 pm

Re: Clicking on a button within a DataGrid Form

Post by cusingerBUSCw5N » Wed Sep 12, 2012 8:29 pm

I don't know why - but it suddenly works. I closed the app, reopened it, and it works.

Go figure

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Clicking on a button within a DataGrid Form

Post by Klaus » Wed Sep 12, 2012 8:36 pm

Hi cusingerBUSCw5N,

great!
That what I always try first, when it comes to erm.. "paranormal activity" in Livecode :D


Best

Klaus

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”