Button in Data Grid

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Button in Data Grid

Post by peaslee » Wed Jul 20, 2011 11:34 pm

Hi,

I have not been successful in adding a push button to my data grid. If anyone can point me to an example I would appreciate it.

Thanks.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

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

Re: Button in Data Grid

Post by Klaus » Thu Jul 21, 2011 12:33 pm

Hi peaslee,

what did you try so far?
What should that button do?

In any case you need a datagrid of type "Form"!




Best

Klaus

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Re: Button in Data Grid

Post by peaslee » Thu Jul 21, 2011 6:10 pm

I want a button with the little pencil icon so the user, by clicking it, will open a stack to edit the record.

The closest I came to success was following the "How to I work with Checkboxes in a Data Grid Example". I can get that to run properly, but I can't seem to get a push button in the Row Template.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

townsend
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 430
Joined: Sun Feb 13, 2011 8:43 pm
Location: Seattle, USA

Re: Button in Data Grid

Post by townsend » Thu Jul 21, 2011 6:29 pm

This tutorial shows how to put a checkBox in a DataGrid.
I think the process is the same for buttons.
Data Grid Helper Plugin - How Do I Create a Checkbox in a Column?

Download the trial version here: DataGrid Helper Plugin.

Otherwise coding gets very involved-- modifying DataGrid Templates and Behavior Scripts.

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Re: Button in Data Grid

Post by peaslee » Sun Jul 24, 2011 6:52 pm

I've had some success - the button and sample data appear. However, I can't figure out how to get column names, nor can I get the button to do something simple like return the data in its row.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

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

Re: Button in Data Grid

Post by Klaus » Mon Jul 25, 2011 12:17 pm

Hi peaslee,

again, what did you script so far for the button? 8)


Best

Klaus

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Re: Button in Data Grid

Post by peaslee » Mon Jul 25, 2011 5:56 pm

Here's what I scripted as a test. The row has trhe button and two label fields. The label fields do show data.

Code: Select all

on mouseUp
    local tLastName
    local tFirstName
    
    put the text of field "lblLastName"   of me into tLastName
    put the text of field "lblFirstName"  of me into tFirstName
    
    answer info tLastName & ", " & tFirstName
end mouseUp
This causes an error and displays code that I assume is part of the underlying system.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Location: California
Contact:

Re: Button in Data Grid

Post by dglass » Mon Jul 25, 2011 6:03 pm

'me' in this context is probably not the row of the data grid.

I suspect you'll need to get the index (or line) the button is in, and then use dgDataOfIndex (Line) to retrieve the data array.

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Button in Data Grid

Post by Zryip TheSlug » Mon Jul 25, 2011 7:17 pm

Klaus wrote:Hi peaslee,
In any case you need a datagrid of type "Form"!
Dear Klaus,

Buttons, images, fields or what ever you want, can be used indifferently in datagrid templates linked to a form or a column.


Here is an example:

Image

The properties window is a datagrid table with two columns. The "Value" column contains different objects such as menus, rectangles, buttons, etc...

peaslee wrote:Here's what I scripted as a test. The row has trhe button and two label fields. The label fields do show data.

Code: Select all

on mouseUp
    local tLastName
    local tFirstName
    
    put the text of field "lblLastName"   of me into tLastName
    put the text of field "lblFirstName"  of me into tFirstName
    
    answer info tLastName & ", " & tFirstName
end mouseUp
This causes an error and displays code that I assume is part of the underlying system.
peaslee wrote:I want a button with the little pencil icon so the user, by clicking it, will open a stack to edit the record.

The closest I came to success was following the "How to I work with Checkboxes in a Data Grid Example". I can get that to run properly, but I can't seem to get a push button in the Row Template.
Dear Bruce,

Where did you added the buttons scripts? Directly in the buttons or in the column behavior?


Best regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Re: Button in Data Grid

Post by peaslee » Mon Jul 25, 2011 7:39 pm

Slug,

I put the button's script in the column behavior.

Bruce
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Button in Data Grid

Post by Zryip TheSlug » Mon Jul 25, 2011 8:30 pm

peaslee wrote:Slug,

I put the button's script in the column behavior.

Bruce
How many columns do you have ?
- Only one with 2 fields (first and last name) and a button
- Three columns (a first name column, a last name column and a column with a button)
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

peaslee
Posts: 20
Joined: Wed Feb 16, 2011 8:36 pm
Location: Site Y

Re: Button in Data Grid

Post by peaslee » Mon Jul 25, 2011 10:33 pm

Zryip TheSlug wrote:
peaslee wrote:Slug,

I put the button's script in the column behavior.

Bruce
How many columns do you have ?
- Only one with 2 fields (first and last name) and a button
- Three columns (a first name column, a last name column and a column with a button)
Three columns: a button and two fields.
Bruce Peaslee
Windows 7 Home Premium (Service Pack 1)
ACPI x-64 based PC 9GB RAM

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Button in Data Grid

Post by Zryip TheSlug » Mon Jul 25, 2011 11:01 pm

peaslee wrote: Three columns: a button and two fields.
Ok. In this case, as point out by dglass, "me" is not the row of the datagrid. For datagrid table, consider "me" as the cell in the row. Inside the cell which contains the button, you will not be able to get a value in a field located in another cell.


Assuming your two text columns are named:
- Last Name
- First Name

A possible solution is to use the getDataOfIndex function of the datagrid library. This function will help you to get a value inside a column in the datagrid data.
You will learn more informations about this function by reading this lesson:
http://lessons.runrev.com/spaces/lesson ... or-Column-


Add this script in the column behavior of the column button:

Code: Select all

on mouseUp pTheButton
   if (pTheButton is 1) then
      if (the short name of the target is "My Button") then
            put the dgIndex of me into tTheIndex
            answer info getDataOfIndex(tTheIndex, "Last Name") && getDataOfIndex(tTheIndex, "First Name")
      end if
   end if
end mouseUp

Best,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”