Delete a row in a data grid?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
akazakana
Posts: 7
Joined: Mon May 11, 2009 3:15 am

Delete a row in a data grid?

Post by akazakana » Tue May 12, 2009 12:00 am

Does anyone know how to delete a row in a data grid? With a plain old field, you could set a mouseup to get the line number of a click and then do "delete line...of me."

I understand how to get the row number when you click on a data grid using "dgline of me." But then what?

Thanks.

(By the way, I absolutely love data grids. It's made a night-and-day improvement in the presentation of information in a current project.)

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Tue May 12, 2009 2:11 pm

Take a look at DeleteIndex and DeleteLine in the Data Grid API. Those should do what you need.[/url]
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

akazakana
Posts: 7
Joined: Mon May 11, 2009 3:15 am

Post by akazakana » Tue May 12, 2009 3:13 pm

Thanks for the help. Deleteindex works like a charm except for one little wrinkle. I can delete but not if the data grid only contains one row. Put another way, I can keep deleting rows one after the other using the following lines except when there is only one row left. Any solution? Thanks.

put the dgindex of me into tLine
put "deleteindex " & tLine into tCutRow
send tCutRow to group "DataGrid1"

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Tue May 12, 2009 3:18 pm

Where is the script? Who "of me" is could affect the behavior. Try this in the data grid group script. It works for me.

Code: Select all

on deleteKey
    put the dgHilitedIndex of me into theIndex 
    DeleteIndex theIndex 
end deleteKey
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

akazakana
Posts: 7
Joined: Mon May 11, 2009 3:15 am

Post by akazakana » Tue May 12, 2009 3:33 pm

No dice, I'm afraid. Using the code you suggested, I can hilite the remaining row but still can't delete it.

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Tue May 12, 2009 3:48 pm

Hmm, have you been editing the data grid scripts at all? Does it work if you quit and restart Rev? If neither of the above then can you send a stack to me?
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

akazakana
Posts: 7
Joined: Mon May 11, 2009 3:15 am

Post by akazakana » Tue May 12, 2009 5:26 pm

I tried restarting but that didn't work. It's just a minor matter at this point, so I'll take you up on your offer of sending a stack when it's a bit more presentable if I may.

Thanks for all the help.

ronn
Posts: 26
Joined: Sun Apr 09, 2006 6:14 pm

Post by ronn » Tue May 19, 2009 1:05 am

Trevor, I'm having the same problem as the original poster. Your method of using the Delete key does work correctly.

But what I'm trying to do is put a small Delete button inside the datagrid (form) so that it appears on each populated row of the grid. I then put code inside that button:

Code: Select all

on mouseUp
    put the dgHilitedIndex of me into theIndex 
    DeleteIndex theIndex 
end mouseUp
This works fine for every row except if there is only one row left in the grid in which case the row won't delete. Actually, I think the row is deleted in the background but it visually remains in the grid until the form is closed and reopened.

Please let me know if that makes no sense and I can send a small sample. Thanks.

... Ron

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Post by trevordevore » Tue May 19, 2009 1:50 am

Try one of two things:

a) Use send in time to delete the index so that the data grid doesn't try to delete the button that is calling "DeleteIndex".

Code: Select all

send "DeleteIndex theIndex" to the dgControl of me in 0 seconds
b) Put the mouseUp in the data grid control and check if the target is the button that should perform the delete.
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

ronn
Posts: 26
Joined: Sun Apr 09, 2006 6:14 pm

Post by ronn » Tue May 19, 2009 3:05 am

Ta da!! Both of the suggested methods worked for me. Thanks very much Trevor.
... Ron

Post Reply