Referencing one button in a Datagrid

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
friday
Posts: 158
Joined: Mon May 09, 2011 3:01 pm

Referencing one button in a Datagrid

Post by friday » Thu Aug 02, 2012 10:10 am

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
Using LiveCode 9.0.1 for Mac/PC/iOS
MacBook Pro 2019 16GB
macOS Monterey v12.4
2.6 GHz 6-Core Intel Core i7

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

Re: Referencing one button in a Datagrid

Post by Klaus » Thu Aug 02, 2012 11:43 am

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

friday
Posts: 158
Joined: Mon May 09, 2011 3:01 pm

Re: Referencing one button in a Datagrid

Post by friday » Fri Aug 03, 2012 12:08 am

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
Using LiveCode 9.0.1 for Mac/PC/iOS
MacBook Pro 2019 16GB
macOS Monterey v12.4
2.6 GHz 6-Core Intel Core i7

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

Re: Referencing one button in a Datagrid

Post by Klaus » Fri Aug 03, 2012 12:29 pm

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

friday
Posts: 158
Joined: Mon May 09, 2011 3:01 pm

Re: Referencing one button in a Datagrid

Post by friday » Fri Aug 03, 2012 7:38 pm

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
Using LiveCode 9.0.1 for Mac/PC/iOS
MacBook Pro 2019 16GB
macOS Monterey v12.4
2.6 GHz 6-Core Intel Core i7

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

Re: Referencing one button in a Datagrid

Post by Klaus » Fri Aug 03, 2012 8:45 pm

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)

Post Reply