Page 1 of 1
datagrid text fields
Posted: Wed Feb 22, 2012 10:59 am
by slowdash
hi and thank you in advance, im doing some sort of a shopping cart app with livecode. I have a datagrid that shows the information of the ordered items "item name", quantity ordered" and "price" . I have textboxes as container for the quantity which the user can edit anytime. In case they want to edit the quantity, they would just type in the amount in the text box and then click a button to update it. My question is, how can i loop though the new values of the textboxes inside the datagrid.
Re: datagrid text fields
Posted: Wed Feb 22, 2012 2:42 pm
by dunbarx
I would extract the data from the datagrid by using either the "dgtext" or the "dgData". The first places all the data into an ordinary variable, the second into an array. Then repost. So the method is:
1- Extract the data.
2- Process the data
3- Restore the data.
In other words, you do not loop through the objects within the structure of the dataGrid itself, you process the data outside of it.
Craig Newman
Re: datagrid text fields
Posted: Thu Feb 23, 2012 12:56 am
by slowdash
im actually pretty stumped on this(as im absolutely new with livecode/hypercard),
can you please show me some code, to loop through the values of the textfield inside the datagrid?
Re: datagrid text fields
Posted: Thu Feb 23, 2012 5:34 am
by dunbarx
You already have a dg, right? Getting the "dgtext" yields a tab and return delimited data set, that could go right into an excel spreadsheet.
In a button, place:
on mouseUp
put the dgText of group "yourDataGrid" into temp
set the clipboardData to temp
end mouseup
Try pasting into a spreadsheet. Works, right?
But you don't want to do that.
I am assuming you have a bit of data, so now write this:
on mouseUp
put the dgText of group "yourDataGrid" into temp
set the itemdel to tab
put "Voila!" into item 1 of line 2 of temp
set the dgText of group "yourDataGrid" into temp
end mouseup
Extracted this way, with the itemDel set to tab, allows you to access any "cell". As I said, you get the data out, process it, and restore it. The "dgText" or the "dgData" if you like arrays, are properties of the dataGrid, which is a group. You get and set those properties as needed. A datagrid, just like the clipboardData, is not a container, so you need to do it this way.
Can you write a repeat loop? I am not sure how experienced you are, since even long time scripters are sometimes newbies where datagrids are concerned. I am one of those. Write back if you need (or just want) to.
Craig Newman
Re: datagrid text fields
Posted: Wed Feb 29, 2012 2:40 am
by FireWorx
Thanks Craig,
When I was using table fields to display my data from an SQL Database query I was able to lock the text of the field and then return the line and item of the line on mousedown with the clickline comand. That way i would know which record and field to edit. How can I do that with datagrids?
Dave
Re: datagrid text fields
Posted: Wed Feb 29, 2012 3:27 am
by FireWorx
Figures out one way to do it.
on mousedown
put the short name of the target into tvar
put word 2 of tvar into tvar
put the dgText of me into temp
answer line tvar of temp
end mousedown
Then extract the unique ID record # from item 1 of temp and edit the record in the database. Thanks for getting me started!
Dave
Re: datagrid text fields
Posted: Wed Feb 29, 2012 4:22 am
by dunbarx
You are on your way. I believe that this sort of excercise is more useful that just jumping into dataGrid machanics, which I believe does an injustice to the learning process. Even if roundabout, and missing a single instance of functionality that would do the same thing in one shot, I think you are better served by far.
But look here, and in the nearby sections of this lesson:
http://lessons.runrev.com/s/lessons/m/d ... -or-column
One day, I will make sense of the dozens and dozens of messages that are generated by merely clicking in a dg cell. Open a clean message watcher and test it.
Craig Newman
Re: datagrid text fields
Posted: Sat Mar 03, 2012 8:42 am
by FireWorx
Hi,
I am using datagrid helper and have a data grid that is tracking the status of fleet of vehicles. Currently the status column for each vehicle is either "GREEN", "RED", or "YELLOW" I want to show a green, red, or yellow image in an adjacent column of the same row if the status column for that row is "GREEN" "YELLOW" or "RED" and hide the other images.
Anyone?
Thanks,
Dave