How to add a new row in my datagrid and remove as well
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
How to add a new row in my datagrid and remove as well
Hi friends.
I have a datagrid that involves cars, year model, kilometer and price.
I'm trying to make two buttons, one that adds cars to the grid and one that removes it.
BUT, when I remove one of the rows I also want that to be stored in some sort of field that shows that the car has been sold. So when the row is removed, it basically shows that it's been sold on another field.
I want a button that when I click on it, it will add another row asking for what car it is, what year model, kilometers it driven and price.
This is what I have for now:
https://prnt.sc/2yYGLUlmgltW
Thanks in advance
I have a datagrid that involves cars, year model, kilometer and price.
I'm trying to make two buttons, one that adds cars to the grid and one that removes it.
BUT, when I remove one of the rows I also want that to be stored in some sort of field that shows that the car has been sold. So when the row is removed, it basically shows that it's been sold on another field.
I want a button that when I click on it, it will add another row asking for what car it is, what year model, kilometers it driven and price.
This is what I have for now:
https://prnt.sc/2yYGLUlmgltW
Thanks in advance
Re: How to add a new row in my datagrid and remove as well
Hi Curiousbystander,
1. add data
Ask your user what he/she want to add and store everything into a variable.
Then put this info into one TAB delimited line:
2. Where do you want to store the info about sold cars?
We need to know this before we can proceed.
Howeer you can extract the data the user wants to delete first with:
Best
Klaus
1. add data
Ask your user what he/she want to add and store everything into a variable.
Then put this info into one TAB delimited line:
Code: Select all
...
put tMerke & TAB & tModell & TAB & tKM & TAB & tPris into tNewLineData
## Here the command to add data to a datagrid of type TABLE:
dispatch "AddLine" to group "Your datagrid here" with tNewLineData
## If you do not supply the second and third parameter tColumns and tLine then
## LC will append a new line at the end of your datagrid.
...
We need to know this before we can proceed.
Howeer you can extract the data the user wants to delete first with:
Code: Select all
...
## What line is selected:
put the dghilitedline of grp "Your datagrid here" into tLine
## Now fetch the DATA in this line
put the dgDataOfLine[tLine] of grp "Your datagrid here" into tData
## Set itemdel to TAB
put item 1 of tData into tMerke
put item 2 of tData into tModell
## etc...
## So you can store whatever you need from these infos later...
...
Klaus
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
Klaus wrote: ↑Mon Oct 17, 2022 1:38 pmHi Curiousbystander,
1. add data
Ask your user what he/she want to add and store everything into a variable.
Then put this info into one TAB delimited line:2. Where do you want to store the info about sold cars?Code: Select all
... put tMerke & TAB & tModell & TAB & tKM & TAB & tPris into tNewLineData ## Here the command to add data to a datagrid of type TABLE: dispatch "AddLine" to group "Your datagrid here" with tNewLineData ## If you do not supply the second and third parameter tColumns and tLine then ## LC will append a new line at the end of your datagrid. ...
We need to know this before we can proceed.
Howeer you can extract the data the user wants to delete first with:BestCode: Select all
... ## What line is selected: put the dghilitedline of grp "Your datagrid here" into tLine ## Now fetch the DATA in this line put the dgDataOfLine[tLine] of grp "Your datagrid here" into tData ## Set itemdel to TAB put item 1 of tData into tMerke put item 2 of tData into tModell ## etc... ## So you can store whatever you need from these infos later... ...
Klaus
...
I was just thinking storing the info on the sold cars on like next card right, just like a list of what is sold. Go to the next card, then the removed ones are on a list that shows what cars are sold.
Re: How to add a new row in my datagrid and remove as well
OK, then just add the infos to that field:
You get the picture...
Code: Select all
...
## What line is selected:
put the dghilitedline of grp "Your datagrid here" into tLine
## Now fetch the DATA in this line
put the dgDataOfLine[tLine] of grp "Your datagrid here" into tData
## Set itemdel to TAB
put item 1 of tData into tMerke
put item 2 of tData into tModell
## etc...
put CR & tMerke after fld "sold cars" of cd "the card with that field of sold cars"
...
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
Can we go back to the first step real quick. Add data part, so like. I have the button, I'll click on it and it should ask what model, km, price, etc. How exactly do I ask and put the answers into the grid. It's been a while since I've done any livecode.Klaus wrote: ↑Mon Oct 17, 2022 1:45 pmOK, then just add the infos to that field:You get the picture...Code: Select all
... ## What line is selected: put the dghilitedline of grp "Your datagrid here" into tLine ## Now fetch the DATA in this line put the dgDataOfLine[tLine] of grp "Your datagrid here" into tData ## Set itemdel to TAB put item 1 of tData into tMerke put item 2 of tData into tModell ## etc... put CR & tMerke after fld "sold cars" of cd "the card with that field of sold cars" ...
Re: How to add a new row in my datagrid and remove as well
You quoted the part that will add the deleted = sold cars!
You mean just a couple of ASK dialogs and storing the users answer in variables:
Now where exactly do you want to store this info about sold cars?
Filed? Another datagrid? On the same card? On card XXX?
You mean just a couple of ASK dialogs and storing the users answer in variables:
Code: Select all
...
## Ask user to enter merk, modell etc...
ask "Merke?"
## User clicked CANCEL:
if the result = "cancel" then
exit to top
end if
put it into tMerke
ask "Modell?"
if the result = "cancel" then
exit to top
end if
put it into tModell
ask "KM?"
if the result = "cancel" then
exit to top
end if
put it into tKM
ask "Pris?"
if the result = "cancel" then
exit to top
end if
put it into tPris
## Now you have all neccessary infos and you can store it wherever you want to.
...
Filed? Another datagrid? On the same card? On card XXX?
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
Klaus wrote: ↑Mon Oct 17, 2022 2:22 pmYou quoted the part that will add the deleted = sold cars!
You mean just a couple of ASK dialogs and storing the users answer in variables:Now where exactly do you want to store this info about sold cars?Code: Select all
... ## Ask user to enter merk, modell etc... ask "Merke?" ## User clicked CANCEL: if the result = "cancel" then exit to top end if put it into tMerke ask "Modell?" if the result = "cancel" then exit to top end if put it into tModell ask "KM?" if the result = "cancel" then exit to top end if put it into tKM ask "Pris?" if the result = "cancel" then exit to top end if put it into tPris ## Now you have all neccessary infos and you can store it wherever you want to. ...
Filed? Another datagrid? On the same card? On card XXX?
Same card, and I suppose a grid again but only with the sold ones yeah.
OH also, how exactly would I use functions JsonImport( ) and JsonExport( ) to convert JSON to array and array to JSON
Re: How to add a new row in my datagrid and remove as well
OK, I already gave half the answer:
Code: Select all
...
## See above for the rest of the script...
...
put it into tPris
## Now you have all neccessary infos and you can store it wherever you want to.
put tMerke & TAB & tModell & TAB & tKM & TAB & tPris into tNewLineData
## Here the command to add data to a datagrid of type TABLE:
dispatch "AddLine" to group "Your other datagrid with the sold cars" with tNewLineData
...
Re: How to add a new row in my datagrid and remove as well
To convert a complete JSON array to LC array and back:Curiousbystander wrote: ↑Mon Oct 17, 2022 2:30 pm...
Oh also, how exactly would I use functions JsonImport( ) and JsonExport( ) to convert JSON to array and array to JSON
Code: Select all
...
## JSON -> Array
put JSONtoArray(the_raw_json_array) into tLCArray
...
## Array -> JSON
put JSONtoArray(tLCArray) into tJSONArray
...
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
Ok! I'm kind of stuck now.
So I click delete. And this happens: https://prnt.sc/mhAPNSvxxXB1
I want it to remove it from the top grid and add it onto the second grid under it. Which is sold cars.
Need a little help.
So I click delete. And this happens: https://prnt.sc/mhAPNSvxxXB1
I want it to remove it from the top grid and add it onto the second grid under it. Which is sold cars.
Need a little help.
Re: How to add a new row in my datagrid and remove as well
Hm, works here in my quick and dirty test:
If you like you can send me the stack and I will take a look.
-> klaus AT major-k.de
?If you like you can send me the stack and I will take a look.
-> klaus AT major-k.de
Re: How to add a new row in my datagrid and remove as well
To actually delete a line use -> DeleteLine
Code: Select all
...
## What line is selected:
put the dghilitedline of grp "datagrid" into tLineNumber
## Delete that line from datagrid:
dispatch "deleteLine" to grp "datagrid" with tLineNumber
...
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
I sent you an email, my friend. Hopefully you can help me a little. Thank you again for your help so farKlaus wrote: ↑Mon Oct 17, 2022 4:02 pmTo actually delete a line use -> DeleteLineCode: Select all
... ## What line is selected: put the dghilitedline of grp "datagrid" into tLineNumber ## Delete that line from datagrid: dispatch "deleteLine" to grp "datagrid" with tLineNumber ...
Re: How to add a new row in my datagrid and remove as well
This script already shows the solution:
In your script "on slettBil" you forget the first part: finding out the currently selected line!
DELETELINE expects a NUMBER but you supplied a string, and we can see the strange result.
Please try to understand what we suggest (see above) and ASK if something is not clear,
otherwise you are wasting our time, we are all volunteers here!
Copy/paste without thinkíng is never a good idea, especially in software programming.
Code: Select all
...
## What line is selected:
put the dghilitedline of grp "datagrid" into tLineNumber
## Delete that line from datagrid:
dispatch "deleteLine" to grp "datagrid" with tLineNumber
...
DELETELINE expects a NUMBER but you supplied a string, and we can see the strange result.
Please try to understand what we suggest (see above) and ASK if something is not clear,
otherwise you are wasting our time, we are all volunteers here!
Copy/paste without thinkíng is never a good idea, especially in software programming.
-
- Posts: 20
- Joined: Wed Sep 07, 2022 4:26 pm
Re: How to add a new row in my datagrid and remove as well
Ok, I fixed the deleting part. But when I delete it right, how do I send the deletion to the "sold car grid", the 2nd grid under it. How do I get it that when I remove it up there it goes to the other grid below.Klaus wrote: ↑Mon Oct 17, 2022 4:43 pmThis script already shows the solution:In your script "on slettBil" you forget the first part: finding out the currently selected line!Code: Select all
... ## What line is selected: put the dghilitedline of grp "datagrid" into tLineNumber ## Delete that line from datagrid: dispatch "deleteLine" to grp "datagrid" with tLineNumber ...
DELETELINE expects a NUMBER but you supplied a string, and we can see the strange result.
Please try to understand what we suggest (see above) and ASK if something is not clear,
otherwise you are wasting our time, we are all volunteers here!
Copy/paste without thinkíng is never a good idea, especially in software programming.