copy data from datagrid

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

copy data from datagrid

Post by bsouthuk » Thu Apr 07, 2011 1:25 pm

Is it possible to copy copy the data in a datagrid into another datagrid? Is the coding simple to acheive this? Not all the data but say for instance I want to copy rows 15-20 from a datagrid and to paste to another datagrid on a a different card.

Your help is most appreciated!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: copy data from datagrid

Post by dunbarx » Thu Apr 07, 2011 3:08 pm

Hi.

Get the dgText, extract lines 15-20, and set the dgtext of the other datagrid to the new data.

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: copy data from datagrid

Post by bsouthuk » Thu Apr 07, 2011 3:14 pm

Thanks for this mate but I'm pretty new to working with datagrids - could you help me out with the code?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: copy data from datagrid

Post by dunbarx » Thu Apr 07, 2011 5:31 pm

Do you have a dataGrid running with data already in it? And another datagrid to receive the information? If so, in a button script, say:

on mouseUp
set the dgText of grp "targetDatagrid" to line 15 to 20 of the dgText of grp "sourceDatagrid"
end mouseup

Datagrids are complex in that they are composed of many different fields, graphics, scrollbars, you name it. But there are a few very transparent properties that make dealing with them very simple, at least at a basic level. The dgText is one of those, which you can get and set. It consists of tab and return delimited data that directly populates the datagrid.

Is this clear? If we were dealing with simple fields, would you have more comfort with the idea? In a field, you would do essentially the same thing, but rather:

on mouseUp
put line 15 to 20 of fld "sourceField" into fld "targetField"
end mouseup

Works the same, the difference being that fields are containers, where you can "put" data, whereas dataGrids are not, so you have to get and set properties. Once you get used to the difference, it is no longer an issue. For example, scripts also are not containers, they are properties of an object. You cannot change a script by putting data into them, as in a field. Their contents are accessable by getting and setting. Here is a simple hack for an existing button script:

on mouseUp
get the script of button "foo"
put return & "destroyComputer" after line 1 of it
set the script of button "foo" to it
end mouseUp

Write back if this is not clear.

Craig Newman

Post Reply