How to determine if a datagrid "contains" a value.

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
CAsba
Posts: 371
Joined: Fri Sep 30, 2022 12:11 pm

How to determine if a datagrid "contains" a value.

Post by CAsba » Fri Mar 24, 2023 11:55 am

Hi
My user will be entering a lot of data about a component product of an in-house manufactured product. I want to allow the user to enter a value of 777.77 when the true value is not to hand, so she can continue to input further data, with an opportunity to edit 777.77 later. Also, the datagrid is to not function and invoke an answer message, warning that 777.77 is still in the datagrid, and must be edited with the true value before the datagrid can be used. It's therefor necessary to determine if the datagrid contains a value of 777.77.
I tried

Code: Select all

  if group "datagrid 1" contains "777.77" then
      put 99 into fld "type"
   end if
but got the message, it is not a container.
Anybody got any idea of what syntax would work?

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

Re: How to determine if a datagrid "contains" a value.

Post by Klaus » Fri Mar 24, 2023 11:59 am

Hi CAsba,

if your datagrid is of type TABLE you can:

Code: Select all

...
if the dgtext of grp "datagrid 1" contains "777.77" then
## Do your thing...
...
"the dgtext" of a datagrid is the TAB and CR delimited text content.
"the dgdata" of a datagrid is the same but wrapped into an array.


Best

Klaus

CAsba
Posts: 371
Joined: Fri Sep 30, 2022 12:11 pm

Re: How to determine if a datagrid "contains" a value.

Post by CAsba » Fri Mar 24, 2023 12:05 pm

Thank you Klaus, very prompt, much appreciated.

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

Re: How to determine if a datagrid "contains" a value.

Post by Klaus » Fri Mar 24, 2023 12:09 pm

At your services, Sire! :-)

stam
Posts: 2717
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to determine if a datagrid "contains" a value.

Post by stam » Fri Mar 24, 2023 8:32 pm

Remember that dgText is actually generated from dgData; the 'native' data format for the data grid is array, not text.
dgText is generated as a developer convenience (or so I think I read somewhere anyway).

So you can just apply array methods, in particular filter:

Code: Select all

put the dgData of group "<data grid name>" into tArray
filter elements of tArray where each["<key name/column name>"] contains <data to search for> -- if multiple keys then just and|or them
assuming you store the total data in a custom property or something so you don't lose it, you can then assign the array to the datagrid to 'filter' the data grid for your search so it only shows rows that fulfil search criteria:

Code: Select all

set the dgData of group "<data grid name>" to tArray
Just another way of doing the same thing...

HTH
S.

CAsba
Posts: 371
Joined: Fri Sep 30, 2022 12:11 pm

Re: How to determine if a datagrid "contains" a value.

Post by CAsba » Sat Mar 25, 2023 7:18 pm

Thanks, Stam, that should be quite handy.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”