Datagrid form, resizable, multiple fields, click 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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Thu Sep 13, 2012 7:28 pm

I have succeeded in setting up a datagrid form, getting data to multiple fields in it, and making it resizable. For me, that's pretty good.
Now, the last step is to be able to click on a specific line in the datagrid to go to the next card.

Seems easy..BUT...when I set up the object script, it will only fire when you click on the Rect that was put into pcontrolRect for resizing. I have tried to put other Rects into pcontrolRect, but have failed.

I have tried putting everything in one Rect, but then it won't resize...

So...I need help please. Here is the code that works for resizability - but it only recognizes a click when you click on theFieldRect (which is my field col3)

Code: Select all

on LayoutControl pControlRect
    
local theFieldRect

## label new field
put the rect of field "label" of me into theFieldRect2
put item 3 of pControlRect - 5 into item 3 of theFieldRect2
set the rect of field "label" of me to theFieldRect2

##resizes field to fit content

put item 2 of thefieldRect2 + the formattedheight of field "label" of me - the bottommargin of field "label" of me into item 4 of theFieldRect2
set the rect of field "label" of me to thefieldRect2

## new field webname 
put the rect of field "webname" of me into theFieldRect3
put item 2 of pControlRect +1 into item 2 of theFieldRect3
put item 3 of pControlRect -5 into item 3 of theFieldRect3
set the rect of field "webname" of me to theFieldRect3

##resizes field to fit content

put item 2 of thefieldRect3 + the formattedheight of field "webname" of me - the bottommargin of field "webname" of me into item 4 of theFieldRect3
set the rect of field "webname" of me to thefieldRect3

## new field date_added 
set the top of field "date_added" of me to the bottom of field "date_added" of me
put the rect of field "date_added" of me into theFieldRect4
put item 2 of pControlRect +15 into item 2 of theFieldRect4
put item 3 of pControlRect -5 into item 3 of theFieldRect4
set the rect of field "date_added" of me to theFieldRect4

##resizes field to fit content

put item 2 of thefieldRect4 + the formattedheight of field "date_added" of me - the bottommargin of field "date_added" of me into item 4 of theFieldRect4
set the rect of field "date_added" of me to thefieldRect4

## original field col3 expands field to fill width

set the top of field "col3" of me to the bottom of  field "label" of me +10
put the rect of field "Col3" of me into theFieldRect
put item 3 of pControlRect - 5 into item 3 of theFieldRect
set the rect of field "col3" of me to theFieldRect

##resizes field to fit content

put item 2 of thefieldRect + the formattedheight of field "col3" of me - the bottommargin of field "col3" of me into item 4 of theFieldRect
set the rect of field "col3" of me to thefieldRect

##update the bounding rect....

put item 4 of theFieldRect into item 4 of pControlRect

set the rect of graphic "background" of me to pControlRect
 end LayoutControl
Here is the object script for the datagrid

Code: Select all

on mouseUp pBtnNum
   if pBtnNum is 1 then
      put the dgHilitedLines of me into theLine
      if word 1 of the target <> "scrollbar" then
         put the dgDataOfLine[theLine] of group "datagrid 2" into theDataA
         
## theDataA is now an array variable.
## In the case of the Data Grid pictured above the keys of the array are id, label, col3, date_added and webname
 
put theDataA["label 1"] into field tchosen
put theDataA["label 2"] into field ttopic
put theDataA["label 3"] into field tdescript

visual effect "push left fast"
go to card "forum_details"
end if
end if
end mouseUp

cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Thu Sep 13, 2012 7:38 pm

Maybe it's another problem. When I click on the datagrid line, the fields that are NOT in the resizable theFieldRect are editable. Which is crazy, because I turn editable for the datagrid off and I can't see any other controls on the object level for editing...

So...instead of receiving my click to go somewhere, it receives the click to edit the line.

It still could be that I need to combine theFieldRect(s) into one...but then the variable height doesn't work.

So,I need something that creates both variable height and turns off all this editable stuff.

cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Thu Sep 13, 2012 8:05 pm

I did a workaround that works...but it's crazy. Using DataGrid helper, I put another blank field on top of the fields that won't click... Now, everything in the datagrid clicks.

Not the best solution - would appreciate knowing how to do it the right way.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6117
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Datagrid form, resizable, multiple fields, click problem

Post by dunbarx » Thu Sep 13, 2012 10:38 pm

Hmmm.

Hard to see what you are doing, but that is usually my problem, not yours.

Why not just test for the "dgHilitedLine"?

on mouseUp
if the dgHilitedLine of group "yourDG" = yourLine then go card yourPreferredCard
end mouseup

On another note, I believe that a field is only made "editable" (actually a separate itinerant field is overlaid on top of the actual target field) if you double-click. Surely you are not seeing this with a single click?

Craig Newman

cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Fri Sep 14, 2012 5:31 pm

dghilitedline only fires when you click on anything except the editable fields. So the issue is - how do you turn off the editable feature of those fields - when I have already turned off editing on the datagrid level?

The only workaround I have is to put a blank field on top of it that doesn't have this problem.

Klaus
Posts: 11113
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Datagrid form, resizable, multiple fields, click problem

Post by Klaus » Fri Sep 14, 2012 5:43 pm

Hi,

putting an empty "mousedoubleup" handler into the behavior script of your row template
will prevent ALL editing of fields unless you add exceptions!

Something like this:

Code: Select all

on mouseDoubleUp pMouseBtnNum

   ## Or simply exit immediately:
   exit mousedoubleup

   ## Default DG stuff:
   ## local theKey
   ## Example of how to edit the contents of a field.
   ## By passing the index of the record associated with copy of this template being displayed and
   ## a key (array key) 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 the dgProps["allow editing"] of the dgControl of me then
   ## ...
end mouseDoubleUp
Best

Klaus

cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Fri Sep 14, 2012 8:37 pm

theoretically sounds great. Only partially works in practice.

It works on the basic fields in my datagrid. It doesn't work on the field that I set as resizable within the datagrid... That so somehow there must be an "exception" with that one. But I don't know where it is or how to remove it.

Here is the datagrid's behavior script (with your code to stop editing included). field id_desc is editable....the others aren't.

Code: Select all

-- This script defines the behavior of your data grid's custom template. This behavior
-- only applies to 'forms' and not 'tables'.

on FillInData pDataArray
    -- This message is sent when the Data Grid needs to populate
    -- this template with the data from a record. pDataArray is an
    -- an array containing the records data.
    -- You do not need to resize any of your template's controls in
    -- this message. All resizing should be handled in resizeControl.
    
   -- Example:

   set the text of field "Col3" of me to pDataArray["label 1"]
   set the text of field "label" of me to pDataArray["label 2"]
   set the text of field "govlevel" of me to pDataArray["label 3"]
   set the text of field "id_desc" of me to pDataArray["label 4"]
   set the text of field "topic_image" of me to pDataArray["label 5"]

   set the filename of image "image_resource" of me to pDataArray["label 5"]


end FillInData


on LayoutControl pControlRect
    local theFieldRect
    
    -- This message is sent when you should layout your template's controls.
    -- This is where you resize the 'Background' graphic, resize fields and 
    -- position objects.
    -- For fixed height data grid forms you can use items 1 through 4 of pControlRect as
    -- boundaries for laying out your controls.
    -- For variable height data grid forms you can use items 1 through 3 of pControlRect as
    -- boundaries, expanding the height of your control as needed.
        
    -- Example:
    set the right of image "image_resource" of me to item 3 of pControlRect - 5
    set the top of image "image_resource" of me to item 2 of pControlRect + 35
    put the left of image "image_resource" of me into theLeft
    put the rect of image "image_resource" of me into theRectImage
    set the rect of image "image_resource" of me to theRectImage
    
    set the left of field "label" of me to item 1 of pControlRect + 5
    set the top of field "label" of me to item 2 of pControlRect + 5
    put the rect of field "label" of me into theRect0

    set the rect of field "label" of me to theRect0
    
        
    set the left of field "id_desc" of me to item 1 of pControlRect + 5
 
set the top  of field "id_desc" of me to the top of field "label" of me + the formattedheight of field "label" of me + 5
put the rect of field "id_desc" of me into theRect1
put theLeft - 5 into item 3 of theRect1
   
put item 2 of theRect1 + the formattedheight of field "id_desc" of me - the bottommargin of field "id_desc" of me into item 4 of theRect1
set the rect of field "id_desc" of me to theRect1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
set the top of button "link_address" of me to the top of field "id_desc" of me + the formattedheight of field "id_desc" of me + 5
put the rect of button "link_address" of me into theRect2
set the left of button "link_address" of me to item 1 of pControlRect + 5

put item 4 of theRectImage + 20 into tone
put item 4 of pControlRect into ttwo
put max(tone,ttwo) into tuse

put tuse into item 4 of pControlRect                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    set the rect of graphic "Background" of me to pControlRect
end LayoutControl


on ResetData
    -- Sent when data is being emptied because the control is no longer being used to display data
    set the text of field "Label" of me to empty
end ResetData


on PreFillInData
    -- Sent right before new data is going to replace existing data in the control
end PreFillInData


setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your custom template has
    -- changed. By default the "Background" graphic will be highlighted for you. 
    -- You only add script here if you want to further customize the highlight.
    
    -- Example:
    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



on mouseDoubleUp pMouseBtnNum
answer "what"
## Or simply exit immediately:
exit mousedoubleup

## Default DG stuff:
## local theKey
## Example of how to edit the contents of a field.
## By passing the index of the record associated with copy of this template being displayed and
## a key (array key) 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 the dgProps["allow editing"] of the dgControl of me then
## ...
end mouseDoubleUp


on mouseUp pTheButton
  end mouseUp

cusingerBUSCw5N
Posts: 338
Joined: Wed Jul 11, 2012 9:24 pm

Re: Datagrid form, resizable, multiple fields, click problem

Post by cusingerBUSCw5N » Fri Sep 21, 2012 4:12 pm

So simple....
I am filling the fields in the datagrid and don't want them edited, so I need to lock the fields.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”