deleting data grid row and committing db change on save

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

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

deleting data grid row and committing db change on save

Post by jalz » Sun Sep 28, 2014 10:28 pm

Hi Guys,

I'm having difficulty into trying to create a 'process' to delete a record. I've designed an app, where a card loads up and any edits for that card are done through a modal dialog. The dialog window continues to have a save and cancel button which either commits a change or not. My card contains a datagrid, and I have some code (below) which deletes a row of data in a datagrid.

Code: Select all

on MouseUp
   local tSelectedRowList
   
   put the dgHilitedIndexes of grp "myGrid" into tSelectedRowList
   
   if (tSelectedRowList is not empty) then
      answer "Really delete this line?" with "Delete" or "Cancel"
      if (it is "Delete") then
         send "DeleteIndex" && tSelectedRowList to grp "myGrid"
      end if
   end if
end MouseUp
 
I know with the code above I can insert in a sql delete query to remove the offending record however I have a save/cancel button on this dialog card. I want to use the save button to delete the the records in the database file (cancel button should not delete records in db even though datagrid may have been deleted). What I can't figure out is how I can pass the deleted ID's of the lines so I can delete the appropriate records in my db. Is there any merit in storing the deleted keys as a custom property and if save is clicked I use the keys to delete actual records.

Another thought I had was on the save button, I should delete all the lines corresponding to myGrid and then rewrite all the data in myGrid back to the db. This just sounds very inefficient way of doing it.

Anyone advise me any other ways I can record a deleted/hidden row and then pass on the relevant key(s) of the deleted record(s) on the save button to the delete sql query.

Many thanks
Jalz

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: deleting data grid row and committing db change on save

Post by jalz » Sun Sep 28, 2014 10:55 pm

I've just gone for storing the deleted ID's of dgitems into a field, and when I hot the save button I commit the change to the db. Cant see a better way of doing it.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: deleting data grid row and committing db change on save

Post by Klaus » Mon Sep 29, 2014 2:40 pm

Hi Jalz,
jalz wrote:Cant see a better way of doing it.
there hardly is! :D

OK, I would have saved the info into a custom property of the datagrid group,
but however you save the IDs_to_be_deleted, this is the way to go!


Best

Klaus

Post Reply