Page 1 of 1
Button in Data Grid
Posted: Wed Jul 20, 2011 11:34 pm
by peaslee
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.
Re: Button in Data Grid
Posted: Thu Jul 21, 2011 12:33 pm
by Klaus
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
Re: Button in Data Grid
Posted: Thu Jul 21, 2011 6:10 pm
by peaslee
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.
Re: Button in Data Grid
Posted: Thu Jul 21, 2011 6:29 pm
by townsend
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.
Re: Button in Data Grid
Posted: Sun Jul 24, 2011 6:52 pm
by peaslee
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.
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 12:17 pm
by Klaus
Hi peaslee,
again, what did you script so far for the button?
Best
Klaus
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 5:56 pm
by peaslee
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.
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 6:03 pm
by dglass
'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.
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 7:17 pm
by Zryip TheSlug
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:
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,
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 7:39 pm
by peaslee
Slug,
I put the button's script in the column behavior.
Bruce
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 8:30 pm
by Zryip TheSlug
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)
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 10:33 pm
by peaslee
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.
Re: Button in Data Grid
Posted: Mon Jul 25, 2011 11:01 pm
by Zryip TheSlug
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,