Page 1 of 1

Referencing one button in a Datagrid

Posted: Thu Aug 02, 2012 10:10 am
by friday
Hi

I am travelling further into The Wonderful World of Datagrids...

I'd like to set a specific button in a column of a datagrid to invisible, depending on the setting of a different button in the same datagrid. The data grid looks like this:

Image

The Type column contains a menu option button. When the user selects a Type of "Multi-answer", I want to set the button in the Answer column (for that specific row only) to visible. Any other menu option selected in the Type column should set the button in the Answer column (for that row only) to invisible.

My code for the option menu button in the Type column (initially generated by the Data Grid Helper plugin) is:

Code: Select all

on menuPick pTheMenuItem
    switch the short name of the target
        case "btnType"
            SetDataOfIndex the dgIndex of me, the dgColumn of me, pTheMenuItem
            answer "The dgIndex of me:" & the dgIndex of me    -- My debug line
            switch pTheMenuItem
                case "Multi-answer"
                    set the visible of "btnAnswers[dgIndex]" to true
                    break
                default
                    set the visible of "btnAnswers[dgIndex]" to false
            end switch
            break
    end switch
end menuPick
...and I get the error:
button "coType Behavior": execution error at line n/a (Chunk: error in object expression) near "btnAnswers[dgIndex]", char 1

I was thinking I could reference the button for that particular row by using dgIndex but this is not right. I am new to datagrids and the related concepts. I've searched the manual and forums for an example like this but can't find one. Any pointers would be helpful.

Thank you muchly
Geoff

Re: Referencing one button in a Datagrid

Posted: Thu Aug 02, 2012 11:43 am
by Klaus
Hi Geoff,

You are using ARRAY syntax and even in QUOTES, that not works! :D

Try this:

Code: Select all

on menuPick pTheMenuItem
    switch the short name of the target
        case "btnType"
            SetDataOfIndex the dgIndex of me, the dgColumn of me, pTheMenuItem
            answer "The dgIndex of me:" & the dgIndex of me    -- My debug line
            switch pTheMenuItem
                case "Multi-answer"
                    set the visible of btn "btnAnswers" OF ME to true
                    break
                default
                    set the visible of btn "btnAnswers" OF ME to false
            end switch
            break
    end switch
end menuPick
Presuming that is the name of your buttons.

Or a slight variation using a Mr. Boole 8)

Code: Select all

on menuPick pTheMenuItem
    switch the short name of the target
        case "btnType"
            SetDataOfIndex the dgIndex of me, the dgColumn of me, pTheMenuItem
            answer "The dgIndex of me:" & the dgIndex of me    -- My debug line
            set the visible of btn "btnAnswers" OF ME to (pTheMenuItem = "Multi-answer")
    end switch
end menuPick
Best

Klaus

Re: Referencing one button in a Datagrid

Posted: Fri Aug 03, 2012 12:08 am
by friday
Hi

Thanks for taking the time to reply. I tried that but it gives me the error:
button "CoType Behavior": execution error at line 19 (Chunk: no such object) near "btnAnswers", char 37

It's as if the button "btnAnswers" isn't accessible from the script??

I added:

Code: Select all

answer "The label of btn btnAnswers:" & the label of btn "btnAnswers"
to the script to see if I could reference btnAnswers and that does display the label of the button, so the answer command works okay but the set invisible doesn't.

I am a little confused. (Although, for me, that's nothing new :roll: )

Cheers
Geoff

Re: Referencing one button in a Datagrid

Posted: Fri Aug 03, 2012 12:29 pm
by Klaus
Hi Geoff,

hm...

If that btn "btn Answers" IS in fact part of the datagrid form then
...
set the visible of btn "btnAnswers" OF ME to false
## OF ME is the key!
...
is the correct syntax!
Sorry, need more info here.


Best

Klaus

Re: Referencing one button in a Datagrid

Posted: Fri Aug 03, 2012 7:38 pm
by friday
I found an example in the Datagrid manual that used "the dgControl of me". So, I changed the code to...

Code: Select all

set the visible of btn "btnAnswers" of the dgControl of me to true
and that worked.

Thanks
Geoff

Re: Referencing one button in a Datagrid

Posted: Fri Aug 03, 2012 8:45 pm
by Klaus
AHA!

Yep, that's it, I somehow presumed all the time that this was in the behaviour script of the DG,
where "... of me" would be correct 8)