Page 1 of 1

Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 1:57 pm
by altamative131
Hello Livecode gods,

I am currently trying to figure out how to pull data from an already populated data grid, and put said data into specific fields within my application.

I have a datagrid with the columns of "Name", "Email" and "Location" with a list of users names, emails and locations in them (approx 150 users in the grid)

what I want to do, is when someone types a users name in the search box and clicks the search button, is to populate the correct Name, email and location into the fields I have designated for said information.

any help with this would be great -- I am having the damndest time.

Thanks,
Chris

Re: Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 3:21 pm
by dunbarx
Hi.

It is possible to extract data from a DG using its "native" properties, such as the "DGDataOFLine", etc. An advantage here is that you can access indexes or whatever directly by name.

But if I need to deal with most, or all, of the information in a DG, I have always felt more comfortable by extracting the entire data set using the "dgText". This gives a tab and return delimited data set, which you can do with what you will.

Or you can get the "dgData" if you want to stay in array mode .Check the DataGrid manual for information on all these...

Craig Newman

Re: Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 4:00 pm
by altamative131
Craig,

Thanks for your reply -- now a followup to that is this.

I pulled the dgtext from the datagrid, now I have text that looks like this

Name of user (tab) Location (tab) Email address (tab)

Now how do I take that tabbed information and put the name of the user into the "Name" text field, the location into the "Location" text field and so on? Sorry if I sound like a moron -- just never done this before.

Thanks,
Chris

Re: Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 4:17 pm
by Klaus
Hi Chris,

"the itemdelimiter" is your friend! :D
default itemdel is a COMMA, but you can set it and do something like this:
...
## My example variable DGVar will hold ONE line of your datagrid (= one record)
set itemdel to TAB
put item 1 of DGVar into fld "Name"
put item 2 of DGVar into fld "location"
### etc., you get the picture...
...


Best

Klaus

Re: Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 5:29 pm
by dunbarx
Hi.

What Klaus said.

If you are working with dataGrids and are still learning LiveCode at a beginner's level, you are very brave indeed. Sort of like buying a completely outfitted toolbox, but instead of building a birdhouse, you intend to build a car. Do experiment with the data you have extracted with the dgText. Be able to:

Get any particular line of that text.
Get any item of that line.
Put one item of one line into another item of another.
Interchange two lines.
Interchange two items.

That sort of thing, until you are comfortable with manipulating data while keeping the idea of tabs and returns as the delimiting characters that create the data structure. This is how excel works, if you are familiar with that. Each cell in a line is delimited by a tab from its neighbors. Each line is delimited by a return. Try this. Make an excel spreadsheet, copy the data, and fool around with it in LC as per the above. Do the opposite, going back to excel.

Craig

Re: Pulling data from datagrid to a text field

Posted: Mon Aug 11, 2014 10:37 pm
by sritcp
Hi Chris:

A DataGrid is not a storage mechanism, it is a display mechanism (like a table).
The array (dgData) or the list (dgText) underlying the DataGrid is the storage mechanism.
The DataGrid displays the stored data to the user, who can manipulate it directly on the DataGrid (he can copy, edit, etc.)

Thus, you don't need to extract information from a DataGrid and display in separate fields (unless you want to do that for some specific reason).
You can simply highlight the row that contains the searched-for name.

If you are not using the DataGrid to display information to the user, it may be that you don't need a DataGrid for your purposes.
You can use an array or list or database to store your data.

Regards,
Sri