Selectively retrieving rows from a datagrid

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Selectively retrieving rows from a datagrid

Post by teacherguy » Mon Dec 26, 2011 10:03 pm

Is there a way to find particular lines in a datagrid and collect them in an array? I know I can do this with a repeat loop from an array, but have not been able to do so with a datagrid (or is it just advisable to always take the datagrid to an array first?).

So for example if I have a datagrid of music terms with columns "Term" and "Definition", and I need lines 1, 20, and 300.... how would I structure the repeat loop and an array to put them into? Anything I have tried will just get the first needed line at best.

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Selectively retrieving rows from a datagrid

Post by teacherguy » Mon Dec 26, 2011 11:02 pm

One of my many failed attempts today:

Code: Select all

on makeTheTerms2
   if the visible of group id 160621 of card id 1002 is false then
      put the dgHilitedLines of group "DataGrid 2" into line.number
      if line.number < 1 then 
         answer "Please choose a line first"
         exit makeTheTerms2
      end if
      
      dispatch function "GetDataOfLine" to group "DataGrid 2" with line.number, "Terms" --the terminology definitions I need
      put the result into theLinesToCheck
      replace comma with tab in theLinesToCheck--so I can treat them as words
      
      put 1 into whichLine
      repeat for each word thisWord in theLinesToCheck
         call GetDataOfLine(thisWord) of group id 159323 of card id 1009
         put the result into line whichLine of theNeededTerms
         add 1 to whichLine
         end repeat
      set the dgData of group id 160621 of card id 1002 to theNeededTerms
      show group id 160621 of card id 1002
      dispatch "RefreshList" to group id 160621 of card id 1002
      exit makeTheTerms2
   end if
   if  the visible of  group id 160621 of card id 1002 is true then hide group id 160621 of card id 1002

end makeTheTerms2

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Selectively retrieving rows from a datagrid

Post by dunbarx » Tue Dec 27, 2011 1:34 am

Try either of: the dgDataOfIndex or the dgDataOfLine.

The most intuitive is the dgDataOfLine[tLine], so that dgDataOfLine[3] would return the third line.

Read here:

http://lessons.runrev.com/s/lessons/m/d ... or-Column-

Craig Newman

teacherguy
Posts: 379
Joined: Thu Dec 08, 2011 2:43 am

Re: Selectively retrieving rows from a datagrid

Post by teacherguy » Tue Dec 27, 2011 4:56 am

annnnd, boom just like that, dgDataOfLine. Thanks Craig, I read through all of the API stuff but I wasn't seeing it clearly was I.

Thanks again, and Happy New Year.

Brian

Post Reply