Page 1 of 2
[solved] Identifying a Datagrid
Posted: Wed Jun 28, 2017 10:38 am
by Zax
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.
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 2:23 pm
by sritcp
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
!!!
Regards,
Sri
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 2:45 pm
by dunbarx
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
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 2:56 pm
by Zax
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).
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 3:15 pm
by sritcp
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
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 3:35 pm
by Zax
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.
Re: [HELP] Identifying a Datagrid
Posted: Wed Jun 28, 2017 3:43 pm
by Klaus
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
Re: [HELP] Identifying a Datagrid
Posted: Thu Jun 29, 2017 6:48 am
by Zax
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
Re: [solved] Identifying a Datagrid
Posted: Thu Jun 29, 2017 2:59 pm
by sritcp
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
Re: [solved] Identifying a Datagrid
Posted: Thu Jun 29, 2017 3:09 pm
by Klaus
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!
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
Re: [solved] Identifying a Datagrid
Posted: Fri Jun 30, 2017 6:49 am
by Zax
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.
Re: [solved] Identifying a Datagrid
Posted: Fri Jun 30, 2017 10:29 am
by Klaus
Zax wrote:If a datagrid is grouped with others controls, its "owner" will return this group, and not the card.
Yes, sure, sorry!
I've never have grouped a datagrid with other controls so please excuse this little faux-pas.
Re: [solved] Identifying a Datagrid
Posted: Fri Jun 30, 2017 12:07 pm
by Zax
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.
Re: [solved] Identifying a Datagrid
Posted: Fri Jun 30, 2017 12:51 pm
by Klaus
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
Re: [solved] Identifying a Datagrid
Posted: Fri Jun 30, 2017 2:03 pm
by Zax
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
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