[solved] Identifying a 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

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

[solved] Identifying a Datagrid

Post by Zax » Wed Jun 28, 2017 10:38 am

Hello,

I have a list of name of all controls of a card and I would like to identify Datagrids. At this point, they appears as group "Datagrid 1", and all the subgroups of the datagrids also appear in the list.
I would like to delete all the elements on datagrids from this list.
When looping thru the list, I've tried something like:

Code: Select all

get ""
try
     get the dgControl of group idGroup
 end try
if it <> "" then ... it's a datagrid
but it is always empty.
When sending

Code: Select all

put the dgControl of group "Datagrid 1"
in the message box, it works and returns an ID.

Thanks for your help.
Last edited by Zax on Thu Jun 29, 2017 6:48 am, edited 1 time in total.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: [HELP] Identifying a Datagrid

Post by sritcp » Wed Jun 28, 2017 2:23 pm

Hi Zax:

Did you make sure to parenthesize properly the name of the datagrid while looping?

Code: Select all

on mouseUp
   repeat with i = 1 to 3
      get "" 
      try
         -- get the dgControl of group "DataGrid" & i  -- INCORRECT; WILL RETURN EMPTY
         get the dgControl of group ("DataGrid" & i) -- CORRECT
      end try
      if it is not empty then put it & return after field "tempTry"
   end repeat
end mouseUp
Klaus is the official "parenthetician" on this forum and he may be able to tell you more about it :D !!!

Regards,
Sri
Last edited by sritcp on Wed Jun 28, 2017 2:53 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9579
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: [HELP] Identifying a Datagrid

Post by dunbarx » Wed Jun 28, 2017 2:45 pm

Just off the top of my head, might you identify the owners of all groups, and if they appear to be a dataGrid, then ignore them?

Craig Newman

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [HELP] Identifying a Datagrid

Post by Zax » Wed Jun 28, 2017 2:56 pm

Thanks for you answers :)

@ Sri: it's not a parenthesis problem, as I make a loop based on IDs.

@ Craig: could be the solution.
But I will have to write recursive loops, as, for example the owner of group "dglist" returns group "dgListMask" (Datagrid seems to contain several nested groups).

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: [HELP] Identifying a Datagrid

Post by sritcp » Wed Jun 28, 2017 3:15 pm

Zax:

You could try
if the dgData of control i is not empty ...
(Note that a blank dataGrid just dragged in will have an empty dgData)

Regards,
Sri

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [HELP] Identifying a Datagrid

Post by Zax » Wed Jun 28, 2017 3:35 pm

sritcp wrote:(Note that a blank dataGrid just dragged in will have an empty dgData)
For that reason, this test wouldn't be accurate ;)


@ Craig: finally, it won't work because I don't know names or IDs of Datagrids.

I will try tsting if a group contains another group named "dgAlternatingRowsMask" with childControlNames.

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

Re: [HELP] Identifying a Datagrid

Post by Klaus » Wed Jun 28, 2017 3:43 pm

Hi all,

this is the official "parenthetician" speaking and this is not the issue as Zax pointed out.

I think the problem is not getting the number of Datagrids on the card, but leaving out
all controls belonging to a datagrid from his list of controls. Is that correct?

In that case, maybe you can leave them out directly in your loop collecting all controls like this:

Code: Select all

on mouseUp
   repeat with i = 1 to the num of controls

      ## Control belongs to a datagrid group:
      if the dgcontrol of control i <> EMPTY then
         next repeat
      end if
      put the name of control i & CR after fld "list"
   end repeat
end mouseUp
You get the picture.

And what value does "idGroup" have in your first script?

Code: Select all

...
get the dgControl of group idGroup
...
Best

Klaus

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [HELP] Identifying a Datagrid

Post by Zax » Thu Jun 29, 2017 6:48 am

Hi Klaus,

Your script works!
At the first glance, it looked like mine but I wanted to be sure an I tested it.

Thanks :)
Klaus wrote:

Code: Select all

on mouseUp
   repeat with i = 1 to the num of controls

      ## Control belongs to a datagrid group:
      if the dgcontrol of control i <> EMPTY then
         next repeat
      end if
      put the name of control i & CR after fld "list"
   end repeat
end mouseUp
Klaus

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: [solved] Identifying a Datagrid

Post by sritcp » Thu Jun 29, 2017 2:59 pm

Hi Klaus:

I have two questions relating to your code:

1. Your code would eliminate not only groups nested under a dataGrid but also the dataGrid itself. For example,
put the dgControl of group "DataGrid1"
returns its own name (i.e., not empty).

2. Also, your output list will contain all kinds of controls, not just the dataGrids. How does your code identify the dataGrids?
(OP said "I have a list of name of all controls of a card and I would like to identify Datagrids.")

Thanks,
Sri

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

Re: [solved] Identifying a Datagrid

Post by Klaus » Thu Jun 29, 2017 3:09 pm

Hi Sri,
sritcp wrote:1. Your code would eliminate not only groups nested under a dataGrid but also the dataGrid itself. For example,
put the dgControl of group "DataGrid1"
returns its own name (i.e., not empty).
Yes, refinements will cost an extra fee! :D

To identify a datagrid and nothing of its innerts, you need to check:
...
if word 1 of control i = "group" AND the dgcontrol of control i <> EMPTY AND the owner of control i = (the name of this cd)
...
THEN it is a datagrid.
sritcp wrote:2. Also, your output list will contain all kinds of controls, not just the dataGrids. How does your code identify the dataGrids?
(OP said "I have a list of name of all controls of a card and I would like to identify Datagrids.")
And he also added "... I would like to delete all the elements on datagrids from this list.", so I thought this would be a good compromise
and was just meant as a starting point for the Zax.

Best

Klaus

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [solved] Identifying a Datagrid

Post by Zax » Fri Jun 30, 2017 6:49 am

Klaus wrote:To identify a datagrid and nothing of its innerts, you need to check:
...
if word 1 of control i = "group" AND the dgcontrol of control i <> EMPTY AND the owner of control i = (the name of this cd)
...
THEN it is a datagrid.
If a datagrid is grouped with others controls, its "owner" will return this group, and not the card. :wink:

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

Re: [solved] Identifying a Datagrid

Post by Klaus » Fri Jun 30, 2017 10:29 am

Zax wrote:If a datagrid is grouped with others controls, its "owner" will return this group, and not the card. :wink:
Yes, sure, sorry! :oops:

I've never have grouped a datagrid with other controls so please excuse this little faux-pas.

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [solved] Identifying a Datagrid

Post by Zax » Fri Jun 30, 2017 12:07 pm

Klaus wrote:I've never have grouped a datagrid with other controls so please excuse this little faux-pas.
Neither do I but, as developpers, we have to try to think about all what could happen, even what we think to be weird. ;)

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

Re: [solved] Identifying a Datagrid

Post by Klaus » Fri Jun 30, 2017 12:51 pm

OK, after some thoughts, this should work to identify a datagrid:
...
if word 1 of control i = "group" AND the dgcontrol of control i <> EMPTY AND the dgcontrol of the owner of control i = EMPTY then
...
It is a datagrid :D

Zax
Posts: 431
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: [solved] Identifying a Datagrid

Post by Zax » Fri Jun 30, 2017 2:03 pm

Klaus wrote:if word 1 of control i = "group" AND the dgcontrol of control i <> EMPTY AND the dgcontrol of the owner of control i = EMPTY then
...
It is a datagrid :D
As Datagrid contains nested groups, I'm not sure it will work.

Finally, this is what I've done.
In a first pass, I built a list containing all the IDs of the datagrids with your first script:

Code: Select all

if the dgcontrol of control i <> EMPTY then put the id of contro o & return after dataGridsIdList
This returns Datagrids IDs but also all the Datagrids elements. Furthermore, some Datagrids elements (like graphics) have no dgcontrol.
So, in a second pass, I check if a given control is part of the datagrids previously listed in dataGridsIdList with this function:

Code: Select all

function isControlInDatagrid givenControlId,cardId,dataGridsIdList
   get the id of the owner of control id givenControlId
   if it = cardId then return false
   get lineOffset(it,dataGridsIdList)
   if it = 0 then
      return isControlInDatagrid(it,cardId,dataGridsIdList)
   else return true
end isControlInDatagrid
... and sorry for my poor english ;)

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”