Button in 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
cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Button in a DataGrid Form

Post by cbarnhart » Wed May 29, 2013 8:14 pm

I got an easy one for you experts out there.....I hope
I have a datagrid in a form format. There are 3 fields per record - title , summary, and link. I added a button that I would like the user to be able to click to launch the website in the link field, but how do I get the field "link" for the record in which the button resides?

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: Button in a DataGrid Form

Post by Traxgeek » Thu May 30, 2013 6:53 am

Hi cbarnhart,

I'm no 'expert' but I have worked pretty extensively recently with data grids especially in their 'form' format...

I understand you have 3 fields and a button per record. I understand you want the button click event to jump out to a website link. And I understand that the 'link' is in the 'link' field of the associated record.

IF I'm correct with the above then I would do something like :
(Assuming your 'link' field is called 'fldLink' and your 'link' button is called 'btnLink'

Create a script for the record button in the 'Row Behaviour' script area of the DataGrid :

Code: Select all

on mouseup pMouseButtonNum
   local sTarget, sLink                 --create the two variables we'll need
  
   put the target into sTarget          --This is the name of the button that was clicked
                                        --(ONLY needed if, at some point, you have more than
                                        --one button / record)
   if pMouseButtonNum = 1 then          --Limit the user to a left mouse click (OPTIONAL)
      if "btnLink" is in sTarget then   --OR sTarget = "btnLink", as you like
            put the text of field "fldLink" [b]of me[/b] into sLink
            --here's your link out...
            launch url sLink            --which should look a little like "http://www.myLinkSite.com/"
      end if
   end if
end mouse up
Think this should help. REMEMBER the 'OF ME' when referrig to any controls in a datagrid...

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Button in a DataGrid Form

Post by Klaus » Thu May 30, 2013 12:13 pm

Hi cbarnhart,

here another solution with a script in the button of the template itself and NOT in the behavior:

Code: Select all

on mouseup
  
  ## What is the DATAGRID Index of the clicked row (button)
  put the dgindex of me into tCurrentIndex
  
  ## get the data for this index:
  put the dgDataOfIndex[tCurrentIndex] of grp "your datagrid here..." into tCurrentData
  
  ## Now get the URL from this ARRAY
  put tCurrentData["url"] into tUrl
  
  ## You may want to check if tUrl is empty!
  ## Now do it:
  launch url tUrl
end mouseup
Best

Klaus

cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Re: Button in a DataGrid Form

Post by cbarnhart » Thu May 30, 2013 4:03 pm

Thank you for all the help. I will let you know how it turn out

Post Reply