Populating an option menu in a datagrid table

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Populating an option menu in a datagrid table

Post by phaworth » Fri Nov 27, 2009 12:51 am

Trying to figure out the best way to populate the contents of an option menu in a datagrid column. I have two scenarios.

First scenario is that the data in the option menu needs to be populated once when the card opens and won;t change again until the card is closed and opened again. I'm looking for the best place put the population code so it only gets executed once when the card opens. Feels like the option menu in the Row Template is what should be populated so that I don;t have to populate each copy of the option menu that is displayed in the datagrid. Would that perhaps be a custom behaviour for the option menu?

Second scenario is that the the contents of the option menu in column B changes dependant on the data entered by the user in column A (column A is also an option menu but it's contents fall under the first scenario). I guess the code to do this would be in a menuPick handler for column A, but I'm having a hard time trying to figure out how to refer to the option menu in column B of the same line as column A

trevordevore
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1005
Joined: Sat Apr 08, 2006 3:06 pm
Contact:

Re: Populating an option menu in a datagrid table

Post by trevordevore » Tue Dec 01, 2009 3:39 pm

Scenario A

Use the preopenCard handler to populate the option menu in the row template for the Data Grid. You can get the row template group like this:

put the dgProp["row template"] of group "DataGrid" into theGroup

Scenario B

I don't think there is an easy way to target particular column controls. Here is what I would do. In the FillInData handler for column B you would populate the menu based on the value of column A (GetDataOfIndex(the dgIndex of me, "column A").

When the user updates the option menu in column a just update the internal Data Grid data and the data grid will redraw, updating the column B menu. Here is a slight variation from the example give in the lesson How Can I Store An Option Menu Value When The User Makes a Selection?:

Code: Select all

on menuPick pChosenItem
    -- Store column data
    SetDataOfIndex the dgIndex of me, the dgColumn of me, pChosenItem

    -- Redraw row
    RefreshList
end menuPick
Trevor DeVore
ScreenSteps - https://www.screensteps.com

LiveCode Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode
LiveCode Builder Repos - https://github.com/search?q=user%3Atrevordevore+topic:livecode-builder

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: Populating an option menu in a datagrid table

Post by phaworth » Tue Dec 01, 2009 10:16 pm

Thanks Trevor, sounds like both solutions will qork for me.
Pete

Post Reply