Page 1 of 1

Populating a data grid column with option menus

Posted: Thu May 02, 2013 9:38 am
by steviegoneevil
Hey all, I have two problems i am unable to fix due to what i hope is due to my inexperience.

1) I've downloaded 6.0 and DGH, however i cant get DGH to work, it keeps saying it is corrupted, i've re downloaded it and the result is the same.

2) I am trying to populate a column of a data grid with option menu, but i can't seem to get it to work. I'm not sure whether that's because i'm not editing the template correctly and/or not knowing what code to use in the FillinData part of the behaviour.

Any help would be greatly appreciated.

Thank You

Re: Populating a data grid column with option menus

Posted: Thu May 02, 2013 11:56 am
by Klaus
Hi steveie,

welcome to the forum :D

1. I think you are using the "Community Edition" of Livecode?
In that case I have bad news, password-protected stacks, like the DGH, do NOT work in that Livecode edition :(

2. No idea but it might be a good idea to post (parts of) your script, especially that "fillInData" handler in question.
And some hint on how you set up your template wouldn't hurt either :D


Best

Klaus

Re: Populating a data grid column with option menus

Posted: Thu May 02, 2013 5:39 pm
by steviegoneevil
Thanks for your reply :D

That's the shame about DGH, but ah well.

I looked at the lesson for customizing a column aswell as watching the how to on displaying images in a datagrid and from what i understood..

1)With the data grid selected, go to the inspector, highlight the column you want to change and click the little plus sign next to column behaviour, which opens the editing template window.
2) make sure 'select grouped' isn't selected, then click 'edit group'.
3)(This is where i get confused) Now, when i delete everything and put a option menu button control and then click 'edit group' again, column behaviour is greyed out. However, when i delete everything but the group which is labelled the same as the selected column, and then add the button, i can click it.
4) Looking at tutorials and examples, FillinData needs a property. Below is the default code when the behaviour is opened.

Code: Select all

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 text of field 1 of me to pData
end FillInData
This is the code in the video i saw, using a blank button and images to populate the column

Code: Select all

on FillInData pData
     set the icon of button "flag" of me to (pData & ".png")
end FillInData
Im not sure what i need to write for an option menu button and i think i also have to change ResetData and LayoutControl pControlRect.

Once again, thank you for the reply! :)

Re: Populating a data grid column with option menus

Posted: Thu May 02, 2013 6:35 pm
by Klaus
Hi Steve,

you probably want to set the LABEL for your "option menu" buttons:

Code: Select all

on FillInData pData
    set the LABEL of btn "your option button here" of me to pData
end FillInData
Best

Klaus

Re: Populating a data grid column with option menus

Posted: Fri May 03, 2013 9:18 am
by steviegoneevil
Hey, sorry for the late reply.
I've tried this but there is still no option menu buttons in the column. This is what the behaviour script looks like.

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 "test" of me to pData
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 "test" of me to pControlRect
end LayoutControl


on ResetData
    -- Sent when column data is being emptied because the control is no longer being used to display data
    set the label of button "test" of me to empty
end ResetData


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


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
    if there is a field 1 of me then
        EditFieldText the long ID of field 1 of me, the dgIndex of me, the dgColumn of me
    end if
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 \
                    and the dgColumnIsEditable[the dgColumn of me] of the dgControl of me then
                EditCellOfIndex the dgColumn of me, the dgIndex of me
                exit mouseDoubleUp
            end if
        end if
    end if
    
    pass mouseDoubleUp
end mouseDoubleUp
Any other ideas?

Thanks!

Re: Populating a data grid column with option menus

Posted: Fri May 03, 2013 11:32 am
by Klaus
Hi Steve,

hm, script looks ok so far, what objects are in your "template"?
Did you really add an "option" button? Do you get any errors?


Best

Klaus

Re: Populating a data grid column with option menus

Posted: Fri May 03, 2013 5:11 pm
by steviegoneevil
Hey Klaus,

In the editing template window there is a group called "Row Template" which contains a group called AM (which is the name of the column im trying to populate) and a button called "test" which i added by going to Object --> New Control --> Option Menu. If i delete group "AM" and only have the button, then i am not able to press column behaviour as it is greyed out No errors in the code being shown.

Once again, thanks for replying :)

Re: Populating a data grid column with option menus

Posted: Fri May 03, 2013 5:21 pm
by Klaus
What objects are in group "AM"?
Is the option button part of that group?
Is the datagrid of type "FORM? Check in the inspector...

Re: Populating a data grid column with option menus

Posted: Fri May 03, 2013 5:38 pm
by steviegoneevil
I didn't realise i could click edit group again when that group is selected, in group "AM", there is a field called "_ColumnData_".
No, i added it to the group "Row template" and not the group "AM"
The datagrid is a Table.