Showing the same datagrid in two different cards

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
korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Showing the same datagrid in two different cards

Post by korax_nyx » Mon Jul 30, 2012 10:57 am

Hi:

I'm a total newbie with LiveCode and I'd like to know if I can do this.

I have two different cards in the same stack and I create a datagrid in one card with some columns. Mi question is: Can I show the same datagrid in the other card with different visible columns?

I want to create a datagrid of items with expected values and real values so I'd like to create a datagrid with three columns: "item", "expected value" and "real value". I would like to show the datagrid in one card where the user can fill the datagrid with item names and their expected value in the future, leaving invisible the real value column.

Then I want another screen (the other card) with the same datagrid, where the user can introduce the real value of the item when time comes, so I would like to show the same datagrid with the columns "item" and "real value", leaving "expected value" column invisible in that card.

It's more complicated than that and I really don't want to show only one datagrid in one card with every column visible. Can I do all this? I hope you get the idea.

Thanks in advance for your help, really.

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

Re: Showing the same datagrid in two different cards

Post by dunbarx » Mon Jul 30, 2012 4:38 pm

Sure, use the:

dgColumnIsVisible [COLUMN]

property. The columns will expand and contract based on their original order.

Craig Newman

korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Re: Showing the same datagrid in two different cards

Post by korax_nyx » Mon Jul 30, 2012 6:24 pm

Hi and thanks for the response, but how can I show the same Datagrid in two different cards? As I said I'm a total newbie.

If I copy and paste the datagrid from one card to another, the new datagrid has a different ID and is totally independent.

Thank you very much.

Best regards

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

Re: Showing the same datagrid in two different cards

Post by dunbarx » Mon Jul 30, 2012 6:48 pm

Ah.

The trick is to set the "backGroundBehavior" of the datagrid group to "true". Then any new card cloned from the card that contains groups with that property will automatically contain those groups.

If you have already created the target card, you can use the "place" command to copy that group (with the backGroundBehavior set) onto that target card:

place group id groupID onto card targetCard

Craig Newman

korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Re: Showing the same datagrid in two different cards

Post by korax_nyx » Mon Jul 30, 2012 6:57 pm

You are my hero, Thanks a lot, really.

Best regards, I owe you a beer :D

korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Re: Showing the same datagrid in two different cards

Post by korax_nyx » Mon Jul 30, 2012 10:14 pm

Hi again:

The trick worked because now I clone the card and it appears the same datagrid in the two cards, with the same ID, but when I modify the data in one datagrid (directly editing the cells with a double click) the changes are not shown in the other datagrid when you navigate to the other card :-/ is it possible to do this?

Thanks again and thanks for the patience.

Best regards

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

Re: Showing the same datagrid in two different cards

Post by dunbarx » Mon Jul 30, 2012 11:21 pm

This is normal behavior. It is similar to setting the "sharedText" of a field to "true", where the text will be the same on each card.

For a dataGrid, set the "persistent data" to "false" in the inspector.

Datagrids are still somewhat mysterious to me, though I use them now and then. They are not native controls in LC, though they are composed of native controls.

I don't drink beer much. How about a plane?

Craig Newman

mushincorps
Posts: 1
Joined: Tue Jul 10, 2012 9:43 am

Re: Showing the same datagrid in two different cards

Post by mushincorps » Tue Jul 31, 2012 7:57 am

Hi:

I figured that the persistent data had something to do, I tried that option but it did not work :(

Thank you very much for your help. Don't you like beer? Shame on you ;)

korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Re: Showing the same datagrid in two different cards

Post by korax_nyx » Tue Jul 31, 2012 10:16 am

Hi again:

Ok, I figured out how to do what I want without using two cards, just one card and hiding and showing the necessary columns of the datagrid with a button, so thank you very much about the property clue, but I have another doubt.

I have this three columns in the datagrid: "Month1Estimate", "Month1Real" and "Month1Deviation". I would want a button that, when clicked, calculates the value of column "Month1Deviation" doing a very simple math operation (Month1Estimate - Month1Real) and it should make it for every row filled in the datagrid.

I know how to do that with two fields but not with every row in a datagrid and operating with datagrid data. Do you know some code or example that I could use to take a look at examples?

Thank you very much for your patience, I'm building that plane right now.

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

Re: Showing the same datagrid in two different cards

Post by dunbarx » Tue Jul 31, 2012 1:40 pm

The datagrid is a very convenient gadget for storing and viewing information.

Read up on the following two properties in the dataGrid manual: "the dgText" and the "dgData"

The more transparent solution is to extract the current data set in a handler using the "dgText", process that information, and restore the dataGrid. This is the usual method, and would also apply to a field. You might write a handler that does some number crunching on each line in a set of fields, but usually you place all that information into variables, do the math, and reload the fields. Same with a dataGrid.

Jet, please.

Craig Newman

korax_nyx
Posts: 9
Joined: Mon Nov 27, 2006 11:46 am

Re: Showing the same datagrid in two different cards

Post by korax_nyx » Wed Aug 01, 2012 9:38 am

I suppose that's the way to go, unfortunately it is beyond my knowledge of LiveCode right now :-/ I'll keep trying. Anything (an example, an stack, something) would be much appreciated.

Thank you for your help, really.

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

Re: Showing the same datagrid in two different cards

Post by dunbarx » Wed Aug 01, 2012 3:04 pm

On a blank card, create a datagrid. Name the group "DG1". Make a few buttons.

In one button, put this into its script:

Code: Select all

on mouseUp
   put "name" & tab & "company" & tab & "address" & return & "name2" & tab & "company2" & tab & "name3" into temp
   set the dgText of group "dg1" to temp
end mouseUp
In another button, put this:

Code: Select all

on mouseUp
   put the dgText of group "dg1" into temp
   set the itemDel to tab
   answer line 2 of temp
   put random(99) into item 2 of line 2 of temp
   answer line 2 of temp
   set the dgText of group "dg1" to temp
end mouseUp
Experiment. There is no shortcut possible. Read the excellent DataGrid manual. Pull data out of and restore into your datagrid, Use the inspector to fool around with it. Try to use the array features instead of the plain text ones; in order to pull certain information, you have to use array notation to reference certain aspects of a dataGrid. It takes time,

Craig Newman

Post Reply