Getting values out of DataGrid

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
eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Getting values out of DataGrid

Post by eddje16 » Thu Dec 06, 2012 12:13 pm

Hello,

I have problems getting values out of a Datagrid.

I have this simple DataGrid

col1 col2
Club Plaats (=column title)
DOVO Assen
Roda Raalte
ACV Assen

Now I want to get the bold values based on the Plaats = Assen.

I already have this code, but than I only get the first value, not both values.


put text of field "resultpost" into tNaam2

repeat for each line theLine in theData
dispatch "FindIndex" to group "tabel" with "plaats", tNaam2
end repeat

put the result into theIndex
put the dgDataOfLine[theIndex] of group "tabel" into theMessageB
put theMessageB["club"] into pZoekenoppostcode
put pZoekenoppostcode into field "post"

Can someone help me out?

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Thu Dec 06, 2012 12:27 pm

Dag Ed,

what you see on the monitor, the datagrid, is only the visual representation of the actual data, which you need to search!
"FindIndex" will always only find one entry.

Do this:

Code: Select all

...
## This is what you are looking for, right?
put text of field "resultpost" into tNaam2

## Get the actual data
put the dgdata of grp "tabel" into tData

## Now loop through all KEYS of this array and check them:
repeat for each key tKey in tData
   if tData[tKey]["plaats"] = tNaam2 then

     ## Collect desired values:
     put tData[tKey]["club"] & CR after tListOfFoundValues
   end if
end repeat

## Delete trailing CR
delete char -1 of tListOfFoundValues
put tListOfFoundValues into fld "post"
...
Groetjes

Klaus

eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Re: Getting values out of DataGrid

Post by eddje16 » Thu Dec 06, 2012 2:10 pm

Thank Klaus,

That worked great.

You make it look so easy! :)

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Thu Dec 06, 2012 2:23 pm

Grag gedaan :-)

A day too late, but anyway:
Sinterklaas Kapoentje
Doe iets in mijn schoentje
Doe iets in mijn laarsje
Dank U Sinterklaasje!

:D

eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Re: Getting values out of DataGrid

Post by eddje16 » Thu Dec 06, 2012 6:03 pm

Haha!

I got from Sinterklaas new socks with my name on it, how cool is that? :)

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Thu Dec 06, 2012 6:09 pm

That is VERY cool! :D

eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Re: Getting values out of DataGrid

Post by eddje16 » Thu Dec 06, 2012 6:51 pm

Man, I'm so happy with it! :)

I don't really want to make another post, but I still have one problem with my stack. Everytime I open it, it is focussing on the first field. I already put some "focus on nothing" in it but nothing seems to work.

Can you have a look at it:

www dropbox com / s / m839lf68tolvi44 / VoetbalNavi1 . 6 . livecode

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Thu Dec 06, 2012 7:04 pm

Hi Ed,
eddje16 wrote:Man, I'm so happy with it! :)
yes, I understand that, socks with your name on them IS definitively cool! :D

To your problem, add this to the "opencard" or "openstack" script:

Code: Select all

on openCard
  send "focus on nothing" to me in 5 millisecs
end openCard
Play a bit with the time until it works for you...

This is neccessary, since you cannot "turn off" the default behavior of Livecode,
which IS to focus on the first field on a card everytime you go to that card.


Best

Klaus

eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Re: Getting values out of DataGrid

Post by eddje16 » Fri Dec 07, 2012 10:55 am

I know!

Jealous? :)

Your solution worked.....of course.. :)

Next problem is with GPS. It won't work on my Android device.

try
mobileStartTrackingSensor "location", true
put mobileSensorReading("location", true) into tLocation
mobileStopTrackingSensor "location"
set the itemdelimiter to comma
if the number of items in tLocation = 3 then
put item 1 of tLocation into pLat
put item 2 of tLocation into pLon
end if

end try

:roll: :roll:

Is it the device itself or the code?

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Fri Dec 07, 2012 11:04 am

Hi Ed,
eddje16 wrote:Jealous? :)
A bit! :D
eddje16 wrote:Next problem is with GPS. It won't work on my Android device.

Code: Select all

...
try
      mobileStartTrackingSensor "location", true
      put mobileSensorReading("location", true) into tLocation
      mobileStopTrackingSensor "location"
      set the itemdelimiter to comma
      if the number of items in tLocation = 3 then
         put item 1 of tLocation into pLat
         put item 2 of tLocation into pLon
      end if    
   end try
...
Is it the device itself or the code?
Hm, since I do not develop for mobile I can only guess.
Did you check if the device has a "sensor" with "mobileSensorAvailable"?


Best

Klaus

eddje16
Posts: 21
Joined: Wed Nov 21, 2012 2:41 pm

Re: Getting values out of DataGrid

Post by eddje16 » Fri Dec 07, 2012 11:18 am

Thought so! :)

Yes, the sensor is available, I checked it.

Klaus
Posts: 13858
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Getting values out of DataGrid

Post by Klaus » Fri Dec 07, 2012 11:42 am

Ah, OK.

Maybe you should post your question right to the ANDROID forum (Hint, Hint!) 8)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”