Datagrid SetDataOfLine problem

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
bonbon
Posts: 62
Joined: Thu Jul 17, 2008 11:48 pm

Datagrid SetDataOfLine problem

Post by bonbon » Sun Mar 04, 2012 8:04 pm

After months of trying (sad, I know) I have almost got a datagrid table with a checkbox in one column working. However, in the onMouseUp handler, I get the following message:
The handler: SetDataOfLine has reached the recursion limit of 400000
Execution will be terminated to prevent hanging
My datagrid has only 2 columns: "Name" (free format text) and "Paid" (either "T" or "F"; this is the column with the checkbox).

Here is the handler: (it's in the Column Behaviour for the "Paid" column)

Code: Select all

on mouseUp pMouseBtnNum
   if pMouseBtnNum is 1 then
      # Update internal value in data grid
      if the hilite of the target is true then
         SetDataOfLine the dgLine of me, "Paid", "T"
      else
         SetDataOfLine the dgLine of me, "Paid", "F"
      end if
   end if
Without this code, the checkboxes can be checked & unchecked with no problem, but of course the datagrid contents are not being changed.

Please would someone put me out of my misery ?

(I'm using Rev 3.5 on XP home)

Pete

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid SetDataOfLine problem

Post by dunbarx » Sun Mar 04, 2012 9:38 pm

Does this fix it? If so, might you have somthing else sending "mouseUp" back to the target? You have no obvious repeat loops. Just a thought.

on mouseUp pMouseBtnNum
if pMouseBtnNum is 1 then
# Update internal value in data grid
if the hilite of the target is true then
SetDataOfLine the dgLine of me, "Paid", "T"
exit to top
else
SetDataOfLine the dgLine of me, "Paid", "F"
exit to top
end if
end if

bonbon
Posts: 62
Joined: Thu Jul 17, 2008 11:48 pm

Re: Datagrid SetDataOfLine problem

Post by bonbon » Sun Mar 04, 2012 10:32 pm

Thank you for looking at this - much appreciated. I'm afraid the "exit to top" still doesn't fix it, though. The only code in the whole stack is that which is in the "Column behaviour" script for the "Paid" column.

Just in case (as I really don't know what I'm doing in this respect), here is the entire Column Behaviour script. Everything except FillInData, LayoutControl and MouseUp is default code. It bombs out both with and without the "exit to top" in the on MouseUp code.

Code: Select all

-- This script defines the behavior of a table column's custom template.

on FillInData pData
    -- This message is sent when the Data Grid needs to populate
    -- this template with the column data. pData is the value to be displayed.
    
    -- Example:
    #set the label of button 1 of me to pData
    set the hilite of button 1 of me to (pData is "T")
end FillInData


on LayoutControl pControlRect    
   -- This message is sent when you should layout your template's controls if your template is a group.
   -- If your template is not a group then there is no work to do here.
   -- You can use items 1 through 4 of pControlRect as boundaries for laying out your controls.
   
   -- Example:
 
   set the rect of button 1 of me to pControlRect
end LayoutControl


setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your column template has
    -- changed. You only add script here if you want to customize the highlight.
    
    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


getprop dgDataControl
    -- Required by library so that it can locate your control.
    return the long id of me
end dgDataControl


-- Data grid will call EditValue if a user action asks to edit cell content.
command EditValue
    EditFieldText the long id of field 1 of me, the dgIndex of me, word 1 to -2 of the short name of me
end EditValue


on mouseDoubleUp pMouseBtnNum
    -- Example of how to edit the contents of a field (assuming the column template this is
    -- associated with is a field).
    -- By passing the index of the record linked to the copy of this template and the name of the
    -- column being edited the data grid will automatically save the changes the user
    -- makes and refresh the UI by calling FillInData and resizeControl.
    if pMouseBtnNum is 1 then
        if word 1 of the target is "field" then
            ## word 1 to -2 because of unique numbers (i.e. 0001, 0002) that the data grid adds to each
            ## copy of this template that is made.
            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 pMouseBtnNum
   if pMouseBtnNum is 1 then
      # Update internal value in data grid
      if the hilite of the target is true then
         SetDataOfLine the dgLine of me, "Paid", "T"
         exit to top
      else
         SetDataOfLine the dgLine of me, "Paid", "F"
         exit to top
      end if
   end if
end mouseUp
Pete

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid SetDataOfLine problem

Post by dunbarx » Sun Mar 04, 2012 11:03 pm

Hmmm.

What happens if you comment out the "mouseDoubleUp" handler?

Can you step through the "mouseUp" handler and see if it branches off somewhere?

Craig Newman

bonbon
Posts: 62
Joined: Thu Jul 17, 2008 11:48 pm

Re: Datagrid SetDataOfLine problem

Post by bonbon » Sun Mar 04, 2012 11:21 pm

Tried commenting out mouseDoubleUp: no difference.

I tried "step into next statement"; it crashes as soon as it hits either of the SetDataOfLine statements.

Do you know if there is an alternative way to set the grid data ?

[Got to go now ... will check in tomorrow as & when work allows]

bonbon
Posts: 62
Joined: Thu Jul 17, 2008 11:48 pm

Re: Datagrid SetDataOfLine problem

Post by bonbon » Mon Mar 05, 2012 5:32 pm

In case anyone else is struggling with this ... sorted !

I tried using

Code: Select all

SetDataOfIndex the dgIndex of me, "Paid", "T"
instead of

Code: Select all

SetDataOfLine the dgLine of me, "Paid", "T"
and it works.

Thanks Craig for your time and ideas, and for getting my poor old brain into "investigate" mode - it's not used to it !

Pete

Post Reply