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
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Wed May 22, 2013 3:04 pm
I'm having issues deleting a line in a data grid when the code is placed within the "Delete" button of the row of the DG. If I place a button outside of the DG and place the code, it works fine....(I understand for the most part that you have to refer to the "dgControl of me" when referring to a particular button that resides within a row template, but I can't seem to figure out the best syntax for accomplishing this. I will provide the code in the behavior script to show what I am doing. Below is a picture of a row for illustration purposes.
Code: Select all
## Behavior script generated by the DataGrid Helper's Script Builder
## 5/20/13 - 10:57 PM
global vLine
on FillInData pDataArray
if (pDataArray["label 1"] is a color) then
set the backcolor of graphic "Background" of me to pDataArray["label 1"]
end if
set the text of field "orderItem" of me to pDataArray["orderItem"]
set the text of field "OrderInfo" of me to pDataArray["OrderInfo"]
set the text of field "total" of me to pDataArray["total"]
set the visible of button "Edit Order" of me to (pDataArray["label 2"] is not false)
end FillInData
command EditValue
switch the short name of the target
case "orderItem"
EditFieldText the long id of field "orderItem" of me, the dgIndex of me,"orderItem"
break
case "OrderInfo"
EditFieldText the long id of field "OrderInfo" of me, the dgIndex of me,"OrderInfo"
break
case "total"
EditFieldText the long id of field "total" of me, the dgIndex of me,"total"
break
end switch
end EditValue
on mouseDoubleUp pMouseBtnNum
if pMouseBtnNum is 1 then
if (word 1 of the target is "field") then
if the dgProps["allow editing"] of the dgControl of me then
EditValue
exit mouseDoubleUp
end if
end if
end if
pass mouseDoubleUp
end mouseDoubleUp
on mouseUp pTheButton
if (pTheButton is 1) then
switch the short name of the target
case "Background"
break
case "Edit Order"
answer "Add your action here"
break
case "Special Instructions"
answer "Add your action here"
break
--THIS IS WHERE I HAVE MY SCRIPT THAT IS CAUSING ISSUES--
case "Delete"
dispatch "deleteIndex" to grp "DataGrid" card "total" of me with vLine
break
end switch
end if
end mouseUp
on LayoutControl pControlRect
set the rect of graphic "Background" of me to pControlRect
set the left of fld "total" of me to the left of btn "Edit Order" of me
set the right of btn "Edit Order" of me to item 3 of pControlRect - 30
put the left of btn "Edit Order" of me into theLeft
put the rect of fld "OrderInfo" of me into theRect
put theLeft -10 into item 3 of theRect
set the rect of fld "OrderInfo" of me to theRect
put the rect of fld "orderItem" of me into theRect
put theLeft -10 into item 3 of theRect
set the rect of fld "orderItem" of me to theRect
end LayoutControl
setprop dgHilite pBoolean
if pBoolean then
set the foregroundcolor of me to the dgProp["hilited text color"] of the dgControl of me
else
set the foregroundcolor of me to empty
end if
end dgHilite
-- Utility
getprop dgDataControl
-- Required by library so that it can locate your control.
return the long id of me
end dgDataControl
on mouseDown
put the dgLine of me into vLine
end mouseDown
--THIS IS WHERE I HAVE MY SCRIPT THAT IS CAUSING ISSUES--
case "Delete"
dispatch "deleteIndex" to grp "DataGrid" card "total" of me with vLine
break
[img]
http://forums.runrev.com/download/file. ... ew&id=2003
[/img]
-
Attachments
-

- ScreenGrab.tiff (21.97 KiB) Viewed 4186 times
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Wed May 22, 2013 3:41 pm
Hi Kenny,
## dispatch "deleteIndex" to grp "DataGrid" card "total" of me with vLine
1. here a "OF card "total" is missing
2. but the description is not neccessary "...to grp "DataGrid" with vLine2 is enough
But the problem is that a control cannot "delete" itself while processing a script.
Try this:
Code: Select all
...
case "Delete"
## "SEND" the command with a little delay (1 tick = 1/60 second)
## to give the button time to "finish" it "self destruction" script :-)
send "deleteindex vLine" to grp "DataGrid" in 1
##dispatch "deleteIndex" to grp "DataGrid" card "total" of me with vLine
break
...
Hint: The current INDEX of a datagrid is NOT neccessarily the currently selected LINE!
So you better decide to use ONE of them:
Code: Select all
global vLine
...
on mouseDown
put the dgINDEX of me into vLine
end mouseDown
...
Best
Klaus
-
KennyR
- Posts: 256
- Joined: Thu Jan 19, 2012 4:25 am
Post
by KennyR » Wed May 22, 2013 3:57 pm
Hi Klaus....Thank you for your help! This seems to work great, but for some reason, if there is only 1 item left in the DG, it will not delete the item...I'm sure I can find a work around, but I am not sure why it will not delete the final entry in the DG...
* never mind....I am new at using the DGhelper and it seems you have to open the script editor through DGhelper each time you edit the script and then apply it to get it to take....Thanks Klaus!!
Last edited by
KennyR on Wed May 22, 2013 4:30 pm, edited 1 time in total.
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Wed May 22, 2013 4:29 pm
Hmm, no idea...
Can you "answer the result" right after your "deleteindex vLine" handler?
Maybe this will give us a hint.
-
alessandropisoni
- Posts: 12
- Joined: Fri Jul 07, 2006 2:14 pm
-
Contact:
Post
by alessandropisoni » Mon Jun 24, 2013 11:42 am
Hello everyone
I have a strange problem. the development mode - dispatch "refreshList" to group "Weather" with the dgHilitedIndex of group "Weather"
works perfectly. When I create the runtime instruction dispatch me a window with ascribed Execution error and a Close button. I commented each line of code and I saw that it is the one that generates the error. What else could it be otherwise? thanks