LiveCode LessonsLiveCode Data Grid Working With Data Grids (Forms & Tables)How Can I Store An Option Menu Value When The User Makes a Selection?

How Can I Store An Option Menu Value When The User Makes a Selection?

This lesson will demonstrate how to update the data associated with a row in a data grid when the user makes a selection from an option menu.

Example Data Grid

Example Data Grid

Here is the data grid we will be working with. Col 2 has been customized with an option menu. What we are going to do is update the data associated with a row to reflect the selection the user makes in the option menu.

Edit Column Behavior

Edit Column Behavior

We need to customize the column behavior. From the Columns pane (1) in the Property Inspector select Col 2 and then click the Column Behavior button (3).

FillInData

FillInData

In the FillInData handler we are setting the menuhistory based on the value of pData that is passed in.

menuPick

menuPick

We can add a a menuPick handler to the column behavior script in order to accomplish our goal. When the user makes a selection from the option menu the menuPick message is sent by the engine. We can then use the SetDataOfIndex command to update the value for the column. The parameters for SetDataOfIndex are the index, the column name and the new value. Since the above script is in a column behavior we can use the dgIndex of me (1) for the index and the dgColumn of me (2) for the column name.

The Behavior In Action

The Behavior In Action

Here is what the data grid's internal array looks like before making a menu selection.

After making a selection for row 2 (1) we can see that the internal value was updated (2).

4 Comments

Daniel Shapiro

This is great but is it possible to store data in a different column when making a selection from and option menu?

If so, how is this done?

Trevor DeVore

Yes. Rather than passing in 'the dgColumn of me' to SetDataOfIndex, pass in the column name you want to set.

Daniel Shapiro

something like this:

SetDataOfIndex the dgIndex of me, the dgColumn ["Price1"], pChosenItem

??

Trevor DeVore

You just need to pass in the column name as the second parameter:

SetDataOfIndex the dgIndex of me, "Price1", pChosenItem

Add your comment

E-Mail me when someone replies to this comment