DataGrid help needed.

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
CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

DataGrid help needed.

Post by CAsba » Fri Apr 07, 2023 12:49 pm

Hi,
I'm making a DG for products, of various types.
One particular type is a manufactured-in-house product.
This product consists of component type products that are already listed; the component products may be sized to spec, for example the manufactured product includes 2 (say) lengths of timber, cut from a longer purchased piece of timber.
I want to change the code of the component product to become the code of the manufactured product & the code of the component product.
This will ensure that a list of the sized component products will appear directly under the manufactured product when the DG is sorted.
It seems to me that the script required is to copy the component product row, then pasted as a new row, then code-edited. The user can then edit the size (and hence the product cost, which will be totalled with other sized component costs to become the cost of the manufactured product). I'm stuck on how to script to copy a row (where the user has been instructed to place the cursor), then paste it back in as a new row.
Any ideas ?

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

Re: DataGrid help needed.

Post by Klaus » Fri Apr 07, 2023 1:18 pm

Hi CAsba,

if you mean that the user had selected/hilited the row in question with this:
(where the user has been instructed to place the cursor)
then you can:

Code: Select all

...
## Get the complete data array:
put the dgData of grp "you dg here..." into tArray

## Get the selected/hilited row:
put the dgHilitedIndex of grp "your dg here..." into tIndex

## Add the copy at the bottom of the datagrid:
dispatch "addData" to grp "your dg here..." with tArray[tIndex]
...
If that is what you are after. :-)

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9733
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: DataGrid help needed.

Post by dunbarx » Fri Apr 07, 2023 3:20 pm

I use dataGrids now and then, and invariably do all processing "outside".

AS Klaus mentioned, you can extract the entirety of the contents of the dataGrid with either the "dgData", which gives an array, or the 'dgText" which gives an ordinary variable. Foe example:

Code: Select all

put the dgText of group "yourDataGrid" into temp
Once you have that, you can then write handlers to modify that variable as needed. Then just:

Code: Select all

set the dgText of group "yourDataGrid" to temp
For simple changes, you can work directly inside the DG. But for big stuff, that is how I do it.

Craig

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: DataGrid help needed.

Post by CAsba » Fri Apr 07, 2023 4:42 pm

Many thanks. I'll give it a try..

stam
Posts: 2739
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: DataGrid help needed.

Post by stam » Fri Apr 07, 2023 5:26 pm

CAsba wrote:
Fri Apr 07, 2023 12:49 pm
Hi,
I'm making a DG for products, of various types.
One particular type is a manufactured-in-house product.
This product consists of component type products that are already listed; the component products may be sized to spec, for example the manufactured product includes 2 (say) lengths of timber, cut from a longer purchased piece of timber.
I want to change the code of the component product to become the code of the manufactured product & the code of the component product.
This will ensure that a list of the sized component products will appear directly under the manufactured product when the DG is sorted.
It seems to me that the script required is to copy the component product row, then pasted as a new row, then code-edited. The user can then edit the size (and hence the product cost, which will be totalled with other sized component costs to become the cost of the manufactured product). I'm stuck on how to script to copy a row (where the user has been instructed to place the cursor), then paste it back in as a new row.
Any ideas ?
Easily done, but not sure how you plan to allow the change by the user. If done outside the popup, then when updating the cell is easy to do with

Code: Select all

dispatch "SetDataOfIndex" to group "DataGrid" with pIndex, pKey,pValue

Alternatively you can also enter code in the fillInData handler for the column behavior, so the it populates the cell with an appropriate value. Note that you can access the values in other columns so you adjust data in fillInData with

Code: Select all

getDataOfIndex(the dgIndex of me, "<column name>") 
HTH
S.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”