Data Grid Won't Display Row Template

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
Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Data Grid Won't Display Row Template

Post by Quinton B. » Wed May 31, 2017 1:29 am

Here's the code:

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 visible of field "text_UserName_NewAccount" to true
   set the visible of field "text_Age_NewAccount" to true
   set the visible of field "text_FirstName_NewAccount" to true
   set the visible of field "text_MiddleName_NewAccount" to true
   set the visible of field "text_LastName_NewAccount" to true
   set the visible of field "text_Password_NewAccount" to true
   set the visible of field "text_ConfirmPassword_NewAccount" to true
   set the visible of field "text_Email_NewAccount" to true
   set the visible of field "text_ConfirmEmail_NewAccount" to true
   set the visible of field "text_PhoneNumber_NewAccount" to true
   set the visible of field "text_ConfirmPhoneNumber_NewAccount" to true
   set the visible of field "text_SecurityQuestion1_NewAccount" to true
   set the visible of field "text_SecurityQuestion2_NewAccount" to true
   set the visible of field "text_Residence_NewAccount" to true
   set the visible of field "text_City_NewAccount" to true
   set the visible of field "text_State_NewAccount" to true
   set the visible of field "text_ZipCode_NewAccount" to true
   set the visible of field "text_Country_NewAccount" to true
   set the visible of button "button_SignUp_Mentor_NewAccount" to true
   
   
   set the text of field "field_UserName_NewAccount" of me to pDataArray["UserName"]
   set the text of field "field_Age_NewAccount" of me to pDataArray["Age"]
   set the text of field "field_FirstName_NewAccount" of me to pDataArray["FirstName"]
   set the text of field "field_MiddleName_NewAccount" of me to pDataArray["MiddleName"]
   set the text of field "field_LastName_NewAccount" of me to pDataArray["LastName"]
   set the text of field "field_Password_NewAccount" of me to pDataArray["Password"]
   set the text of field "field_ConfirmPassword_NewAccount" of me to pDataArray["ConfirmPassword"]
   set the text of field "field_Email_NewAccount" of me to pDataArray["Email"]
   set the text of field "field_ConfirmEmail_NewAccount" of me to pDataArray["ConfirmEmail"]
   set the text of field "field_PhoneNumber_NewAccount" of me to pDataArray["PhoneNumber"]
   set the text of field "field_ConfirmPhoneNumber_NewAccount" of me to pDataArray["ConfirmPhoneNumber"]
   set the label of button "button_SecurityQuestion1_NewAccount" of me to pDataArray["SecurityQuestion1"]
   set the text of field "field_SecurityQuestion1_NewAccount" of me to pDataArray["SecurityQuestion1Answer"]
   set the label of button "button_SecurityQuestion2_NewAccount" of me to pDataArray["SecurityQuestion2"]
   set the text of field "field_SecurityQuestion2Answer_NewAccount" of me to pDataArray["SecurityQuestion2Answer"]
   set the label of button "button_Residence_NewAccount" of me to pDataArray["Residence"]
   set the text of field "field_ResidenceAnswer_NewAccount" of me to pDataArray["ResidenceAnswer"]
   set the text of field "field_City_NewAccount" of me to pDataArray["City"]
   set the text of field "field_State_NewAccount" of me to pDataArray["State"]
   set the text of field "field_ZipCode_NewAccount" of me to pDataArray["ZipCode"]
   set the text of field "field_Country_NewAccount" of me to pDataArray["Country"]
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:
   
   --    put the rect of field "text_UserName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_UserName_NewAccount" of me to theFieldRect
   --    put the rect of field "text_Age_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_Age_NewAccount" of me to theFieldRect
   --    put the rect of field "text_FirstName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_FirstName_NewAccount" of me to theFieldRect
   --    put the rect of field "text_MiddleName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_MiddleName_NewAccount" of me to theFieldRect
   --    put the rect of field "text_LastName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_LastName_NewAccount" of me to theFieldRect
   --    put the rect of field "text_Password_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_Password_NewAccount" of me to theFieldRect
   --    put the rect of field "text_ConfirmPassword_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_ConfirmPassword_NewAccount" of me to theFieldRect
   --    put the rect of field "text_Email_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_Email_NewAccount" of me to theFieldRect
   --    put the rect of field "text_ConfirmEmail_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_ConfirmEmail_NewAccount" of me to theFieldRect
   --    put the rect of field "text_PhoneNumber_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_PhoneNumber_NewAccount" of me to theFieldRect
   --    put the rect of field "text_ConfirmPhoneNumber_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_ConfirmPhoneNumber_NewAccount" of me to theFieldRect
   --    put the rect of field "text_SecurityQuestion1_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_SecurityQuestion1_NewAccount" of me to theFieldRect
   --    put the rect of field "text_SecurityQuestion2_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_SecurityQuestion2_NewAccount" of me to theFieldRect
   --    put the rect of field "text_Residence_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_Residence_NewAccount" of me to theFieldRect
   --    put the rect of field "text_City_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_City_NewAccount" of me to theFieldRect
   --    put the rect of field "field_State_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_State_NewAccount" of me to theFieldRect
   --    put the rect of field "text_ZipCode_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "text_ZipCode_NewAccount" of me to theFieldRect
   --    put the rect of field "field_Country_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_Country_NewAccount" of me to theFieldRect
   
   --    put the rect of field "field_UserName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_UserName_NewAccount" of me to theFieldRect
   --    put the rect of field "field_Age_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_Age_NewAccount" of me to theFieldRect
   --    put the rect of field "field_FirstName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_FirstName_NewAccount" of me to theFieldRect
   --    put the rect of field "field_MiddleName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_MiddleName_NewAccount" of me to theFieldRect
   --    put the rect of field "field_LastName_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_LastName_NewAccount" of me to theFieldRect
   --    put the rect of field "field_Password_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_Password_NewAccount" of me to theFieldRect
   --    put the rect of field "field_ConfirmPassword_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_ConfirmPassword_NewAccount" of me to theFieldRect
   --    put the rect of field "field_Email_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_Email_NewAccount" of me to theFieldRect
   --    put the rect of field "field_ConfirmEmail_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_ConfirmEmail_NewAccount" of me to theFieldRect
   --    put the rect of field "field_PhoneNumber_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_PhoneNumber_NewAccount" of me to theFieldRect
   --    put the rect of field "field_ConfirmPhoneNumber_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_ConfirmPhoneNumber_NewAccount" of me to theFieldRect
   --    put the rect of button "button_SecurityQuestion1_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of button "button_SecurityQuestion1_NewAccount" of me to theFieldRect
   --    put the rect of field "field_SecurityQuestion1_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_SecurityQuestion1_NewAccount" of me to theFieldRect
   --    put the rect of field "button_SecurityQuestion2_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "button_SecurityQuestion2_NewAccount" of me to theFieldRect
   --    put the rect of field "field_SecurityQuestion2Answer_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_SecurityQuestion2Answer_NewAccount" of me to theFieldRect
   --    put the rect of button "button_Residence_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of button "button_Residence_NewAccount" of me to theFieldRect
   --    put the rect of field "field_ResidenceAnswer_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_ResidenceAnswer_NewAccount" of me to theFieldRect
   --    put the rect of field "field_City_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_City_NewAccount" of me to theFieldRect
   --    put the rect of field "field_State_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_State_NewAccount" of me to theFieldRect
   --    put the rect of field "field_ZipCode_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_ZipCode_NewAccount" of me to theFieldRect
   --    put the rect of field "field_Country_NewAccount" of me into theFieldRect
   --    put item 3 of pControlRect - 5 into item 3 of theFieldRect
   --    set the rect of field "field_Country_NewAccount" of me to theFieldRect
   
   
   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 "field_UserName_NewAccount" of me to empty
   set the text of field "field_Age_NewAccount" of me to empty
   set the text of field "field_FirstName_NewAccount" of me to empty
   set the text of field "field_MiddleName_NewAccount" of me to empty
   set the text of field "field_LastName_NewAccount" of me to empty
   set the text of field "field_Password_NewAccount" of me to empty
   set the text of field "field_ConfirmPassword_NewAccount" of me to empty
   set the text of field "field_Email_NewAccount" of me to empty
   set the text of field "field_ConfirmEmail_NewAccount" of me to empty
   set the text of field "field_PhoneNumber_NewAccount" of me to empty
   set the text of field "field_ConfirmPhoneNumber_NewAccount" of me to empty
   set the label of button "button_SecurityQuestion1_NewAccount" of me to "Chose A Security Question"
   set the text of field "field_SecurityQuestion1_NewAccount" of me to empty
   set the label of button "button_SecurityQuestion2_NewAccount" of me to "Chose A Security Question"
   set the text of field "field_SecurityQuestion2Answer_NewAccount" of me to empty
   set the label of button "button_Residence_NewAccount" of me to "Chose A Security Residence"
   set the text of field "field_ResidenceAnswer_NewAccount" of me to empty
   set the text of field "field_City_NewAccount" of me to empty
   set the text of field "field_State_NewAccount" of me to empty
   set the text of field "field_ZipCode_NewAccount" of me to empty
   set the text of field "field_Country_NewAccount" 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
    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
            switch the short name of the target
                case "Label"
                    put "Label 1" into theKey
                    EditFieldText the long ID of the target, the dgIndex of me, theKey
                    break                 
            end switch
        end if
    end if
    
    pass mouseDoubleUp
end mouseDoubleUp
I have no idear what's wrong with it. I simply want this row template to display for the user to enter data into, then it goes into an sqlite server which is another part (Which works( But I didn't use a Datagrid thought)).
Attachments
Capture02.PNG
This is the Row Template.
Capture01.PNG
This is what it displays as.
Capture01.PNG (9.88 KiB) Viewed 4708 times

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Data Grid Won't Display Row Template

Post by Klaus » Wed May 31, 2017 12:29 pm

Hi Quinton,

sounds and looks like you initially hide all objects in the row template, is that correct?

If yes, that is why you do not see anything in the stack untill the datagrid gets filled.
So show all object in the template and try again.
You better show/hide the complete datagrid for this "effect".

On the other hand using a datagrid for letting the user enter data seems like "overkill" to me.
A datagrid is meant to display one or more "records" in the same "template".


Best

Klaus

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

Re: Data Grid Won't Display Row Template

Post by jameshale » Thu Jun 01, 2017 1:52 am

Klaus is right. A datagrid is not appropriate here.
Regardless of how you have laid out your form template, if there is no data to show there is nothing to see.
The apparent use you have here is for a single entry form.
Much better to simply set this up on a card, group it, and then fill or read it as required.
If all the fields etc of the form are grouped you could even have the group appear or disappear as required (if you want to stay on a card.)
As Klaus said, the data grid is primarily a control for the display of data.
So in this case you might use it to display a list of multiple registrants (either as a table or a form if you wanted something fancy.) However even here it would probably be advised not to use the data grid display for editing the data.

Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Re: Data Grid Won't Display Row Template

Post by Quinton B. » Sat Jun 03, 2017 11:52 pm

Yes, this is meant to be used as an entry form. I have made one without a data grid( all the fields in a group on a card(Which does work)). Just wanted to make it more presentable and easier to use with a data grid. Is there something else that I could use besides using it as a Datagrid, or on a card? :?:

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

Re: Data Grid Won't Display Row Template

Post by dunbarx » Sun Jun 04, 2017 12:03 am

Just wanted to make it more presentable and easier to use with a data grid. Is there something else that I could use besides using it as a Datagrid, or on a card? :?:
I agree. The entire LC world is available for you when creating your entry form. Much of this can also be implemented in a DG of type "form", it is true, but you have far more flexibility with a suite of individual controls, perhaps grouped, as James suggested.

Colors, sizes, fonts, images, the list of properties is endless, and all are individually customizable. And it is easier and more powerful, in my opinion, to manage handlers (likely in the card script) referenced to specific controls. The "target" is your friend in that.

Craig Newman

Post Reply