Page 1 of 1

deleting a line from a datagrid

Posted: Mon May 06, 2013 7:33 am
by rjuan
Hi,
I would like to delete a line of data contain in a global variable wich contain the whole data, those data are presented in a dataGrid group.
I choose the line :

Code: Select all

  put the dgHilitedLines of group "listing" into theLine
put the dgDataOfLine[theLine] of group "listing" into theDataA
Now I have an array that contain the data I want to delete.
I don't know how I can retrieve those data from the global variable.

Assuming that theVariable contain the whole data and theDataFormatted contain the line with "item1 <tab> item2 <tab> etc." , can I simply do :

Code: Select all

replacetext (theVariable, theDataFormatted, "")

Re: deleting a line from a datagrid

Posted: Mon May 06, 2013 12:06 pm
by Klaus
Hi rjuan,

I am not sure I understand you correctly, but deleting a line from a datagrid is done this way:
...
put the dgHilitedLines of group "listing" into theLine
## not neccessary for deleting:
## put the dgDataOfLine[theLine] of group "listing" into theDataA

## Now delete line:
dispatch "deletelines" to grp "listing" with theLine
## Done :-)
...

Best

Klaus

Re: deleting a line from a datagrid

Posted: Wed May 08, 2013 11:10 am
by rjuan
Sorry for explanation.
I do want to delete the line in the variable tLignes that contains the data (item1 tab item2 tab item3 return, etc.), the datagrid contain just a selection of lines.

I turned around the problem like this, it may not be very elegant :

Code: Select all

      answer warning "Vous voulez vraiment détruire l'écriture sélectionnée ?" with "Non" or "Oui"
      if it is "Oui" then 
         put the dgDataOfLine[theLine] of group "listing" into theDataA -- theDataA contains the line to delete
         -- extracting the data from the line and put it into a temporary variable (tmp)
         put theDataA["Date"] & tab & theDataA["Montant"] & tab & theDataA["Libellé"] & tab & theDataA["Ventilation"] & tab & theDataA["Notes"] & tab & theDataA["Compte"] & return into tmp
         -- deleting the line of data in the variable
         replace tmp with "" in tLignes
         -- updating the selection
         majdesecritures
      end if

Re: deleting a line from a datagrid

Posted: Wed May 08, 2013 3:12 pm
by Klaus
Bonjour rjuan,

AHA, now I get it :D
OK, so you have the complete "dgtext" of a datagrid in a variable, right?
And you want to delete the text from that variable that is currently hilited in your datagrid, right?

Do this:

Code: Select all

...
## tLine is the number of the currently hilited line in the datagrid
answer warning "Vous voulez vraiment détruire l'écriture sélectionnée ?" with "Non" or "Oui"
if it is "Oui" then

   ## This will only work if the data in the variable is a 1:1 representation of the datagrid!
   ## Know what I mean?
   delete line tLine of tLignes
   majdesecritures
end if
...
Hope I understood correctly 8)


Best

Klaus

Re: deleting a line from a datagrid

Posted: Thu May 09, 2013 7:09 am
by rjuan
Thanks to Klaus whose understanding is perfect :wink:
In fact the datagrid contain a selection, it may be a search the user did to delete the lines, so not all the lines in the variable are in datagrid and the order may be different.
It's why I use "replace" in the command, LC make the job.
I'm sure there's a best way, if anyone....

Re: deleting a line from a datagrid

Posted: Thu May 09, 2013 11:41 am
by Klaus
Bonjour rjuan,

there is no best way, but a lot of ways to do something in Livecode :D

I would have used another approach with "lineoffset" (mainly because i have no idea of regex, which is ued in "replacetext" 8) ):
...
## 1. get the selected TEXT of the datagrid
put line tLine of the dgtext of grp "listing" into tTextLine

## 2. get its lineoffset in the variable
put lineoffset(tTextLine,tLignes) into tTextLineNumber

## 3. delete that line of the variable
delete line tTextLineNumber of tLignes
...

Not neccessarily better, but different :D


Best

Klaus