Problem removing last row in data grid

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
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Problem removing last row in data grid

Post by doobox » Mon Mar 19, 2012 2:40 pm

Hi there,

I am struggling to understand why the i cant successfully completely remove a row from the data grid only if it is the last row remaining.

I have a button in the row template "deletes row" :

Code: Select all

on mouseUp 
   put the dgHilitedLines of group "DataGrid 1" into theLine
   dispatch deleteLIne to group "DataGrid 1" with theLine
end mouseUp

Then the handler in the behavior script like so :

Code: Select all

on deleteLIne theLine
   lock screen
   set the dgDataOfLine[theLine] of me to empty
   unlock screen
end deleteLIne
So i am observing this working fine, if i am deleting rows and there is more than 1 row in the form.
But when i try and delete the last row, it does not re-draw the form, so still displays the last rows info.

I can tell it's a not refreshing the form after trying to delete the last row, as i have a test button, outside the grid with this code in that will clear that hanging old data from the last row entry :

Code: Select all

on mouseUp
    dispatch RefreshList to group "DataGrid 1"
end mouseUp
Problem is i cant seem to find a way to automate this RefreshList after the last row is deleted from the grid. Placing it in the last line of the deleteLine handler has no effect.
Kind Regards
Gary

https://www.doobox.co.uk

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Problem removing last row in data grid

Post by bangkok » Mon Mar 19, 2012 3:21 pm

You should try to use DeleteIndex

In your datagrid :

Code: Select all

getProp laSelection
   put the dgHilitedLines of me into theLine
   return the dgIndexOfLine [ theLine ] of me
end laSelection
In a button outside the datagrid :

Code: Select all

on mouseup
    put the laselection of grp "mydatagrid"  into tIndex
  dispatch "DeleteIndex" to group "mydatagrid"  with tIndex
end mouseup

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Problem removing last row in data grid

Post by doobox » Mon Mar 19, 2012 3:36 pm

Thank's for the suggestion.. I can see what that's meant to be doing but it does not work here, i am afraid.
What i cant see is why..It makes sense, reading it.
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Problem removing last row in data grid

Post by doobox » Mon Mar 19, 2012 3:39 pm

Dont know why but :

Code: Select all

put the laselection of grp "DataGrid 1"  into tIndex
    dispatch "DeleteIndex" to group "DataGrid 1"  with tIndex
    put tIndex into field "test"
Is showing empty in the test field.

I have the get prop in the data grid behavior script, was that the intention..?

Edited....
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Problem removing last row in data grid

Post by doobox » Mon Mar 19, 2012 3:49 pm

Moved the getProp to the correct location, and have that functioning exactly as you intended from a button outside the data grid.

Problem is the button i want it on is inside the row template..
Putting this code there results in exactly the same behavior as my original code.. If there is only 1 line left in the form, the data is removed but the grid does not refresh.
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Problem removing last row in data grid

Post by doobox » Mon Mar 19, 2012 4:21 pm

Now this is looking weirder by the minute..

I reworked my code.

I now have the below on a button outside the grid :

Code: Select all

on mouseUp
   put the dgHilitedLines of group "DataGrid 1" into theLine
   dispatch "DeleteIndex" to group "DataGrid 1"  with theLine
end mouseUp
So this works as expected, and when i highlight a row and press this button, it deletes and removes the row from the grid.
It will do this without fail for all items highlighted, even the last item.

BUT.. this wont work for the last item if i use the code on a button within the row template.. Works on all items but the last one.. weird right..
WEIRDER..If i use this code, as a completely round the houses way to accomplish my goal it still does not work for the last item in the grid, if there is only one left..
On the button inside the row template :

Code: Select all

on mouseUp 
   dispatch "mouseUp" to button "deleterow" 
end mouseUp
Button "deleterow" is the button outside the grid that works for all items even the last if i actually click it, but not for the last item in list if i script the click this way.. arrrrrrrr..!
Kind Regards
Gary

https://www.doobox.co.uk

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Problem removing last row in data grid

Post by bangkok » Tue Mar 20, 2012 12:27 am

Solution in this stack.

With

Code: Select all

send mouseup to btn "erase" in 0 millisecond
it's working. Without, the line stays.
Attachments
xx.zip
(5.42 KiB) Downloaded 240 times

stam
Posts: 2679
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Problem removing last row in data grid

Post by stam » Mon Jul 19, 2021 7:50 am

Sorry to zombie this old topic but it seems the problem still remains 9 years later... the solution is as @bangkok posted above - but the devil is in the detail...

For the benefit of anyone else coming across this: The embedded button sends a mouseUp to a hidden button outside the datagrid which in turn sends a deleteIndex command back to the data grid and this can now successfully delete the last remaining row, but the key here is it's sent in 0 milliseconds. ie:

Code: Select all

send "mouseUp" to button <hidden button> in 0 milliseconds 
with the hidden button doing the expected deleteIndex, and this now deletes the last row of the data grid as intended.
However it fails if you do not add the in 0 milliseconds!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”