Page 1 of 1

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

Posted: Fri Mar 24, 2023 11:55 am
by CAsba
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?

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

Posted: Fri Mar 24, 2023 11:59 am
by Klaus
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

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

Posted: Fri Mar 24, 2023 12:05 pm
by CAsba
Thank you Klaus, very prompt, much appreciated.

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

Posted: Fri Mar 24, 2023 12:09 pm
by Klaus
At your services, Sire! :-)

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

Posted: Fri Mar 24, 2023 8:32 pm
by stam
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.

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

Posted: Sat Mar 25, 2023 7:18 pm
by CAsba
Thanks, Stam, that should be quite handy.