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
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Thu Dec 05, 2013 2:25 pm
I have a datagrid with data, my idea is when I doubleclick a window opens and I can edit the data there. I want to be able to limit what values can be entered so I do not want the user to be able to edit in the datagrid.
When I doubleclick a row in a datagrid I want to open a new window and bring all of the data from that row with me.
Code: Select all
put the dgHilitedLines of group "mainGrid" into theLine
put the dgDataOfLine[theLine] of group "mainGrid" into theDataA
So I now have the needed data in theDataA and I want to open my "addedit" stacks "addeditWindow" card and be able to read the content of theDataA there. After editing is done I also need to get all the variables back and update the datagrid
Is this how I should do it and can somebody guide me to where I can read how to do it or if it is simple show me?
Thanks in advance!
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10331
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Thu Dec 05, 2013 2:37 pm
Hi.
Is there an issue with simply continuing the handler you already, have, navigating to the stack of interest:
go stack "yourStack"
put theDataA into wherever
What did you really mean by "get all the variables back and update the datagrid"? The dataGrid was not affected by reading data out of it, and your variables are intact, as long as the handler has not ended. Do you have other plans for these?
Craig Newman
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Dec 05, 2013 2:41 pm
Hi Nicke,
in your EDIT stack you need field according to the columns in the datagrid.
Then you need to put the content of the array theDataA into these fields,
I will give an example with 3 columns: name, firstname, age
Code: Select all
## See below:
global the_last_selected_row_in_datagrid
...
put the dgHilitedLines of group "mainGrid" into the_last_selected_row_in_datagrid
## You will need to note this number to be able to write the modified data back
## into the correct line of the datagrid!
put the dgDataOfLine[the_last_selected_row_in_datagrid] of group "mainGrid" into theDataA
## No go to your EDIT card
go cd "addeditWindow" of stack "addedit"
## Now put content of array into the appropriate fields:
put theDataA["name"] into fld "name"
put theDataA["firstname"] into fld "firstname"
put theDataA["age"] into fld "age"
## You get the picture...
...
Now after the user has edited all the data, you need to collect the modified fields into an array and write that back to the datagrid:
Code: Select all
## This needs to go into the EDIT stack or card, I will leave the decision WHEN to do this up to you :-)
global the_last_selected_row_in_datagrid
...
put fld "name" into theDataB["name"]
put fld "firstname" into theDataB["firstname"]
put fld "age" into theDataB["age"]
## Close stack EDIT or whatever...
## Now write the databack into datagrid
set the dgDataOfLine[the_last_selected_row_in_datagrid] of grp "your datagrid here" of cd xyz of stack zxy to theDataB
...
Best
Klaus
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Fri Dec 06, 2013 5:34 pm
Hi Klaus,
I thought that I just needed to use global in one place and did not understand that I need to have it on every place where I need to access that variable. So now I get the data in and put the edited value into theDataB (that needs to be global too, right?)
So after I have put everything back into theDataB I close the stack by "close this stack" but how do the main stack know that I am ready editing and it should update the datagrid? Should I call a function? in the maincard before I close or how do I do it?
Sorry, but I still have a lot to learn.
Best
Nicke
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Dec 06, 2013 5:54 pm
Hi Nicke,
this line:
...
set the dgDataOfLine[the_last_selected_row_in_datagrid] of grp "your datagrid here" of cd xyz of stack zxy to theDataB
..
actually DOES update the datagrid!
Sorry, no capisce
Best
Klaus
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Fri Dec 06, 2013 6:29 pm
Klaus,
ok I feel really stupid now but here is the code for my save button but nothing happens to the datagrid. I have checked that "theLine" has the line number to update and that theDataB includes the only field I am testing with. Do I need to have all the values in the datagrid (only title used in my test, 10 in the datagrid) to test this? I think that I have read somewhere that I need to be in the stack were the datagrid is to update it, or is that not right?
This code is in the addeditWindow card of stack addedit
Code: Select all
on mouseUp
put field "addedit_log" into theDataB[Title]
set the dgDataOfLine[theLine] of group "mainGrid" of cd "mainWindow" of stack "main" to theDataB
close this stack
end mouseUp
What am I missing?
Best Nicke
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Mon Dec 09, 2013 12:21 pm
If I use the same code on the same stack/card were the datagrid is it works but not from another stack/card...
Code: Select all
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" of stack "main" to theDataB
I also tried to dispatch a refresh but without any luck...
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Dec 09, 2013 12:53 pm
Nicke wrote:If I use the same code on the same stack/card were the datagrid is it works but not from another stack/card...
Code: Select all
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" of stack "main" to theDataB
...
Then set "the defaultstack" and see if that works:
...
set the defautlstack to "main"
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" to theDataB
...
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Mon Dec 09, 2013 12:59 pm
Klaus,
I tried to add
but now the main window closes when I press my button and it the addedit stays open...
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Dec 09, 2013 1:12 pm
Yes, after that line -> THIS stack = "main"!
What can we do now?

-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Mon Dec 09, 2013 1:18 pm
Hmm, I did not quite understand...
adding this stack = "main" gives me an error so you did probably mean something else
Code: Select all
set the defaultStack to "main"
this stack = "main"
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" to theDataB
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Dec 09, 2013 1:28 pm
I meant that after setting the defaultstack to stack "MAIN", then "THIS STACK" will resolve to stack "MAIN"!
So, if "THIS STACK" does not work anymore to close your stack, what can you do to finally close that stack?
...
set the defaultStack to "main"
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" to theDataB
## Now the big question: What stack do we need to close if "THIS STACK" does not work anymore?
close ???
...
I am sure you will find the answer!

-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Mon Dec 09, 2013 1:34 pm
Klaus,
ok, I think I got it since I can now close the stack but the datagrid is still not updated
Code: Select all
on mouseUp
put fld "addedit_log" into theDataB["title"]
put "1" into theDataB["ch"]
set the defaultStack to "main"
set the dgDataOfLine[theLine] of group "mainGrid" of card "mainWindow" to theDataB
close stack "addedit"
end mouseUp
-
Klaus
- Posts: 14199
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Dec 09, 2013 1:38 pm
Nicke wrote:ok, I think I got it since I can now close the stack...
Good boy!
See, it was not THAT difficult (but took a while)!
But sorry, no idea about the not updating datagrid.
I never tried to modify a datagrid that is NOT on the current card in the current stack,
since I know that there are problems. Ok, but that will not help you much...
Maybe you can try to FORCE a redraw:
...
dispatch "refreshList" to grp "your datagrid..."
...
-
Nicke
- Posts: 36
- Joined: Thu Nov 28, 2013 11:19 am
Post
by Nicke » Mon Dec 09, 2013 1:45 pm
Ok, I have to rethink my approach then... I want a new window to open up for doing the editing but without the menu that I have in the main window. Any ideas?
Even if I didn't get it to work, I have learned a lot. Thanks Klaus!!!