Using an Option Menu to Get Data from a Data Grid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Using an Option Menu to Get Data from a Data Grid
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).
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 162 times
Re: Using an Option Menu to Get Data from a Data Grid
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.
-
- 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
Hello martimer,
The following statements should help you on the way?
This put all your DataGrid Data into an array with the line number at the highest level of the array.
This gives you the keys (linenumbers) of the lines in your datagrid
This puts the column names (in lines) into the variable tColumnNames.
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.
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
The following statements should help you on the way?
Code: Select all
put the dgData of group "YourDataGridName" into tArrayDataDG
Code: Select all
put the keys of tArrayDataDGinto tKeysOfDG
Code: Select all
put the dgProp["columns"] of group "YourDataGridName" into tColumnNames
Code: Select all
put tArrayDataDG[tLineNbr] into tLineDataArray
put tLineDataArray["ColumnName"] into tDataFromLineAndColumn
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
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
Re: Using an Option Menu to Get Data from a Data Grid
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.
I will look in to the samples MrCoolian posted. Thank you.
Re: Using an Option Menu to Get Data from a Data Grid
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.
Re: Using an Option Menu to Get Data from a Data Grid
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...
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...
Re: Using an Option Menu to Get Data from a Data Grid
I would guess it is because you didn't set the itemDelimiter to tab - Once you do that, you should see the results your looking for
*Edit - I forgot to put in some helpful links
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.
Re: Using an Option Menu to Get Data from a Data Grid
You are right about that itemdelimiter call. Thanks again!
Re: Using an Option Menu to Get Data from a Data Grid
Glad to be of some help