Datagrid column update
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Datagrid column update
Hello, I have a datagrid with 6 columns and 15 rows
I need to change the values in column 2 in all 15 rows
Is that possible by script?
Thanks
I need to change the values in column 2 in all 15 rows
Is that possible by script?
Thanks
Re: Datagrid column update
Hi geo,
yes!
In this case you need to loop through the content, update your columns and "write" the content back to the datagrid:
If your datagrid is of type TABLE then you can also do this with -> the dgtext of grp xy
Best
Klaus
yes!
In this case you need to loop through the content, update your columns and "write" the content back to the datagrid:
Code: Select all
...
## dgdata = an ARRAY of the content
put the dgdata of grp "your dg here" into tArray
repeat for each key tKey in tArray
put "your new value" into tArray[tKey]["name of your column here"]
end repeat
## Now update content of dg:
set the dgdata of grp "your dg here" to tArray
...
Code: Select all
...
## dgTEXT = the content of your dg as TAB and CR delimited text
put the tdgtext of grp "your dg here" into tText
set itemdel to TAB
repeat with i = 1 to the num of lines of tText
put "your new value" into item 2 of line i of tText
end repeat
## Now update content of dg:
set the dgtext of grp "your dg here" to tText
...
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9837
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Datagrid column update
Klaus' answer is a good one, and I have no idea if "split by column" is any faster*, but it's good to be aware of it as it can sometimes be very handy.
With this handler, pList is any tab-delimited table, such as one would get from the DataGrid's dgText; pColNumber is the number of the column you want to replace; pNewColData is a return-delimited list of values you want to replace the specified column with:
* In this case I'm pretty sure this function isn't faster than Klaus' loop, since the DG's internals use an array and this function is dependent on a string. So while "split by column' may be faster than a loop for data already in string form, the overhead of converting the array to a string before passing it to the function, and then back again to put back into the DG, will probably eat a few more microseconds than a loop through the DG's own array.
With this handler, pList is any tab-delimited table, such as one would get from the DataGrid's dgText; pColNumber is the number of the column you want to replace; pNewColData is a return-delimited list of values you want to replace the specified column with:
Code: Select all
function ReplaceColumn pList, pColNumber, pNewColData
split pList by column
put pNewColData into pList[pColNumber]
combine pList by column
return pList
end ReplaceColumn
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Datagrid column update
Hi guys, thanks for your answers
with FourthWorlds method I get:
Type Handler: error in statement
Object Button
Line combine pList by column
Hint ReplaceColumn
With Klaus' method I can only put one new value into all lines, but I have different values for each line
with FourthWorlds method I get:
Type Handler: error in statement
Object Button
Line combine pList by column
Hint ReplaceColumn
With Klaus' method I can only put one new value into all lines, but I have different values for each line
Re: Datagrid column update
Hi geo,
Just as an example (since I don't know where your 'values' are coming from, anymore than they do), you might modify this part of Klaus's example like so:
Klaus and Richard are giving you the 'how' to do it, you have to fill in the blanks.
Just as an example (since I don't know where your 'values' are coming from, anymore than they do), you might modify this part of Klaus's example like so:
Code: Select all
## for sake of argument, lets say that you have a list of new values in a variable tmpList,
## and each line of tmpList matches the item you want in the line in the tText...
repeat with i = 1 to the num of lines of tText
put line i of tmpList into item 2 of line i of tText
end repeat
-
- VIP Livecode Opensource Backer
- Posts: 9837
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Datagrid column update
The function itself is known to work, as I wrote it and tested it in LC before posting.
It will become possible to know what's causing the error when you post the code you used to call it. Offhand I'd guess you're calling it as a command instead of a function, but that's just a guess. Once I see your relevant snippet I'll have you up and running as well as my copy here.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Datagrid column update
Hello
Richard, your right, I wasn't calling it as a function, now it works
bogs, I modified it as you suggested, now it works as well
Thank you very much
Richard, your right, I wasn't calling it as a function, now it works
bogs, I modified it as you suggested, now it works as well
Thank you very much