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!
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.
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?
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?
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
## 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:
## 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
...
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?
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!
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
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
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
...
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!
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
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..."
...
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!!!