How to add a new row in my datagrid and remove as well

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

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to add a new row in my datagrid and remove as well

Post by Klaus » Mon Oct 17, 2022 5:55 pm

Everything is already on this card!
And of course you need to memorize the data BEFORE you delete it, afterwards is too late, don't you think? 8)

Delete script:

Code: Select all

...
## What line is selected:
put the dghilitedline of grp "datagrid" into tLine

## Now fetch the DATA in this line and store it in a variable:
put the dgDataOfLine[tLine] of grp "Your datagrid here" into tData
## tData now contains the complete row: Merke TAB Modell TAB KM TAG Pris

## If you do not need all of the columns, get the one you want to save in "sold cards"
## Set itemdel to TAB
put item 1 of tData into tMerke
put item 2 of tData into tModell
put item 3 of tData into tKM
put item 4 of tData into tPris

## Now store the info you need:
put CR & tMerke after fld "sold cars" 
## if not on the current card, add the exact "address: ... of cd "the card with that field of sold cars"

## Or if you have another datagrid with the same columns as the first one use:
## dispatch "AddLine" to group "Your datagrid here" with tData

## Now we can delete that line from datagrid:
dispatch "deleteLine" to grp "datagrid" with tLineNumber
...

Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Re: How to add a new row in my datagrid and remove as well

Post by Curiousbystander » Mon Oct 17, 2022 8:10 pm

I'll send you an email again, can you look at what I did wrong? I'm having trouble understanding why it's not deleting and moving it to 2nd grid under it.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to add a new row in my datagrid and remove as well

Post by Klaus » Tue Oct 18, 2022 1:17 pm

For the sake of completeness, here is what I wrote in my mail to Adam:
OK, most important, both datagrids need to have the same amount of rows with the same name:
Merke
aarsmodell
Kilometer
Pris

Fix that and then use this handler:

Code: Select all

on slettBil
  ## What line is selected:
  put the dghilitedlines of grp "DataGrid" into tLine

  ## We need to take care of EVERYTHING!
  ## User did not select a line:
  if tLine = EMPTY then
     answer "please select a row!"
     exit to top
  end if

  ## Now fetch the DATA in this line and store it in a variable:
  put the dgDataOfLine[tLine] of grp "DataGrid" into tData
  ## tData now contains an ARRAY with the data of this row

  ## Or if you have another datagrid with the same columns as the first one use:
  ## Use ADDDATA if you want to pass an array like in this case
  dispatch "AddData" to group "gridto" with tData

  ## Now we can delete that line from datagrid:
  dispatch "deleteLine" to grp "DataGrid" with tLine
end slettBil

Curiousbystander
Posts: 20
Joined: Wed Sep 07, 2022 4:26 pm

Re: How to add a new row in my datagrid and remove as well

Post by Curiousbystander » Tue Oct 18, 2022 3:56 pm

Hi again, thank you for everything Klaus. I appreciate it a lot! Very helpful and good at explaining. I've got everything working

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”