Find rows in a datagrid

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Find rows in a datagrid

Post by lohill » Mon Mar 13, 2017 6:38 pm

I am using dgh_FindIndexes to find the comma delimited list of indices of rows in a datagrid that match a certain set of criteria. That is working just fine and I could set the dgHilitedIndexes to identify them. Rather than do that, I would like to delete all the rows that are not in the list of indices. I could dispatch "deleteIndexes" to the datagrid if I had the list of indices that complemented those found. My problem is in finding that list. Any suggestions?

Thanks, Larry

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

Re: Find rows in a datagrid

Post by dunbarx » Mon Mar 13, 2017 7:34 pm

Is the old fashioned way, to get the dgText, do your finagling, and then reset, an option?

I always feel comfortable with this sort of thing because I can use friendly LC gadgetry instead of fearsome DG gadgetry. The two extra steps required are nothing, to me.

Craig Newman

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Find rows in a datagrid

Post by Klaus » Mon Mar 13, 2017 8:01 pm

Hi Larry,

this is how to compute your missing list:
1
2
...
## up to:
the number of lines of your datagrid

-> MINUS: each item in the result of your dgh_FindIndexes function

Get the picture?


Best

Klaus

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Find rows in a datagrid

Post by lohill » Mon Mar 13, 2017 8:38 pm

The "dgh" is not what is giving me the problem and it is very efficient at getting the initial list of the ones I want to keep. It is getting rid of the others where my problem occurs. Here is a bit of the code that I have tried:

Code: Select all

 dgh_FindIndexes the long id of group tGrid, tField, tCondition, tValue
   put the result into tIndexes
   put empty into tToDelete
   put the dgData of group tGrid into tData
   put the number of elements of tData into tCount
   repeat with i=1 to tCount
      put  i  into tString
      put itemOffset(tString,tIndexes) into nPos
      if nPos=0 then
         put i & comma after tToDelete
      end if
   end repeat
   dispatch "deleteIndexes" to group tGrid with tToDelete
The problem comes with itemOffset. When tIndexes="9,10,11" and i=1, nPos turns out to equal 2. Consequently the row whose index is 1 does not get added to tToDelete and is not deleted from the grid.

Larry

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Find rows in a datagrid

Post by Klaus » Mon Mar 13, 2017 9:12 pm

Hi Larry,

add this line right before the repeat loop:

Code: Select all

...
## !
set the wholematches to true
## !
repeat with...
...
Best

Klaus

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Find rows in a datagrid

Post by lohill » Mon Mar 13, 2017 9:53 pm

Thanks Klaus,
That is one I never knew.
Larry

Post Reply