Using an Option Menu to Get Data from a Data Grid

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
martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Using an Option Menu to Get Data from a Data Grid

Post by martimer » Sun Jan 20, 2019 2:33 am

I cannot be the first person to try this and not the last to need help with this. The example is for some sort of sales system, where an order consists of a section of items and then is stored in a separate file, tp later be recalled as necessary.

I suppose I could use databases for this, but the project will only ever be seen by maybe 8 people and will likely be a webpage. The persistence only has to last for the duration of the session and only my (eventually five?) data tables will be accessed.

I would like to use a few Option Menus to make selections from a Data Grid and then use the data related to those selections in some calculations. I know there is a way to populate the Option Menu selections with the appropriate column of the Data Grid, but since these are not user adjustable Data Grids I have not explored that. Makes things easier for me!

So, how do I use the selected Option Menu choice to select the row of the Data Grid? From there I can capture the array of data and use the data from the appropriate column.

After that, I would like to add the selected data to a different Data Grid (call it Orders?) and be able to select an "Order" for modification.

Sample attached, it does not work...

Many thanks in advance. I used to do a fair bit of hobby coding but have not coded for several years. I know some rudiments of the paradigms of LiveCode and am probably just tripping over the differences between this and other environments I(and landing on my dignity).
Attachments
Data Grid Test.livecode.zip
(7.23 KiB) Downloaded 160 times

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by bogs » Sun Jan 20, 2019 10:56 am

I'd ask the question do you really need a datagrid for this? For what you describe, it seems like a simple table would do, i.e. rows & columns of cells.
Image

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Using an Option Menu to Get Data from a Data Grid

Post by mrcoollion » Sun Jan 20, 2019 1:58 pm

Hello martimer,

The following statements should help you on the way?

Code: Select all

put the dgData of group "YourDataGridName" into tArrayDataDG
This put all your DataGrid Data into an array with the line number at the highest level of the array.

Code: Select all

 put the keys of tArrayDataDGinto tKeysOfDG
This gives you the keys (linenumbers) of the lines in your datagrid

Code: Select all

put the dgProp["columns"] of group "YourDataGridName" into tColumnNames
This puts the column names (in lines) into the variable tColumnNames.

Code: Select all

 put tArrayDataDG[tLineNbr] into tLineDataArray
 put tLineDataArray["ColumnName"] into tDataFromLineAndColumn
This gets the data from a line (tLineNbr) and puts it into array tLineDataArray
The following line of code gest the data from a specific column from tLineDataArray

If you need to have the user select a column name In the Option Menu button, the following will populate the optionmenu.

Code: Select all

on mouseDown
   put the dgProp["columns"] of group "YourDataGridName" into tColumnNames
   set the text of btn "SelectStack" to tColumnNames
end mouseDown
For additional DataGrid information see Dictionary and search in Googe for 'LiveCode Datagrid'.
or see URL http://lessons.livecode.com/m/datagrid/ ... a-grid-api

I personally love datagrids and use them a lot..
Hope to have been of some help here....

Regards,

Paul

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by martimer » Sun Jan 20, 2019 6:26 pm

Bogs - You may be completely correct. When I first started looking at this I somehow determined that a simple table would not work, but no longer recall why! (I may be overloaded by paradigm shifts - 40 years of programming gets in the way...) Maybe I m just too used to dealing with databases?

I will look in to the samples MrCoolian posted. Thank you.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by bogs » Sun Jan 20, 2019 10:40 pm

I should add I don't think there is anything wrong with either datagrids or databases, I've used both a lot in other languages.
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by martimer » Mon Jan 21, 2019 1:09 am

I got tired of not understanding how to get data from a Data Grid, so I tried a Table Field. I can get data, just not the right data.

Given the Table Field named "TestTable" with the following data:
Name Age ID
Joe 20 67
Nancy 30 23

Why does:
answer item 1 of line 2 of field "TestTable"

Produce: "Joe 20 67" rather than "Joe"?

Why does:
answer item 2 of line 2 of field "TestTable"

Produce: "" rather than "20"?

How do get that pesky "20"?

Thanks.

I am VERY HAPPY to find that I can get the MenuHistory of an Option Menu to figure out the index value (row #) for that Table (IF that Option Menu is populated with with a column from that table).

EDIT: I should mention that I know how to "Split by Tab" into an array. I was trying to avoid this method of programming and to use "native controls" to help me learn this environment. Nothing "wrong" with the olden days...

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by bogs » Mon Jan 21, 2019 10:35 am

martimer wrote:
Mon Jan 21, 2019 1:09 am
Why does:
answer item 1 of line 2 of field "TestTable"

Produce: "Joe 20 67" rather than "Joe"?
I would guess it is because you didn't set the itemDelimiter to tab -
Selection_001.png
Tab-u-lating...
Once you do that, you should see the results your looking for :wink:

*Edit - I forgot to put in some helpful links :oops:
http://lessons.livecode.com/m/4071/l/75 ... able-field

http://lessons.livecode.com/m/4071/l/58 ... in-a-field

http://lessons.livecode.com/m/4071/l/78 ... able-field
Last edited by bogs on Mon Jan 21, 2019 10:41 am, edited 1 time in total.
Image

martimer
Posts: 39
Joined: Tue Jun 25, 2013 9:24 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by martimer » Tue Jan 22, 2019 4:21 pm

You are right about that itemdelimiter call. Thanks again!

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Using an Option Menu to Get Data from a Data Grid

Post by bogs » Tue Jan 22, 2019 4:43 pm

Glad to be of some help :D
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”