Add line to DataGrid

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
mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Add line to DataGrid

Post by mediaman » Tue Jan 12, 2010 5:36 pm

Hi

I've got problems with adding line to a data grid. I've got a text field, a data grid and a button. The button script is as follows at the moment:

Code: Select all

on mouseUp
put the selectedText into theDataA[1]["LastName"]
lock screen
set the dgData of group "DataGrid 1" to theDataA
unlock screen
end mouseUp
This works fined at the moment – but now I would like to press the button again and again and put different highlighted texts from the textfield into separate lines of the grid. I found the documentation on this but couldn't get it to work.

Could anybody help – much appreciated.
Thanks
mm

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Add line to DataGrid

Post by sturgis » Tue Jan 12, 2010 5:45 pm

Code: Select all

on mouseUp
put the selectedText into theDataA[1]["LastName"] 
lock screen
set the dgData of group "DataGrid 1" to theDataA
unlock screen
end mouseUp
The problem is that theDataA[1]["LastName"] is an array. You are assigning a value to the first entry of an array, into a subarray named "LastName".
So far so good. Then you set the data of the grid you made to that array. Also so far so good. The first time.

The second time you do it, you are still placing your data into the FIRST entry of your array, then again assigning the whole array (with only 1 entry) to the datagrid, so all it would do is change the value for the first line over and over and over.

To do what you actually want, check out this page. http://revolution.screenstepslive.com/s ... Data-Grid-

Technically you could keep adding lines to your grid similar to the way you were trying if you incremented the number in [#] each time but then every single time ALL the data in the grid must be reloaded, so its not the best way to do this. Go to the link above, it is the proper way to accomplish what you're trying to do.

mediaman
Posts: 9
Joined: Tue Jan 12, 2010 5:30 pm

Re: Add line to DataGrid

Post by mediaman » Tue Jan 12, 2010 10:03 pm

Hi Sturgis

Thanks for this – I've tried to use this, but honestly I don't understand
This example script resides inside the Data Grid group script so AddLine is in the message path.
mm

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Add line to DataGrid

Post by sturgis » Tue Jan 12, 2010 10:36 pm

I'm not expert on the message path, but the basic thing here is, if you are executing a script that is outside of the dataGrid itself, it won't be able to find the handlers that are inside the datagrid. If the script Is inside the datagrid itself then it will. thats why the addData handler above uses dispatch. Its because the calling scirpt isn't inside the datagrid. So if you're executing your script from a button you added somewhere in your project, and want to use addLine you need to "dispatch" the command ot the group at which point it will take it over, find the right handler and execute it.

Converting the addline example, it would be

dispatch "addLine" to group "datagrid1" with theRowData, theDataColumns, theLineNo

You can read more about the message path here, http://www.runrev.com/developers/lesson ... g-started/
as well as http://www.fourthworld.com/embassy/arti ... _path.html so you can get a better understandign of things.
mediaman wrote:Hi Sturgis

Thanks for this – I've tried to use this, but honestly I don't understand
This example script resides inside the Data Grid group script so AddLine is in the message path.
mm

Post Reply