Datagrid Table LayoutControl Issue

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
Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Datagrid Table LayoutControl Issue

Post by Gage » Sun Aug 17, 2014 10:24 am

Hello,

I have a DG Table that has a column which displays either a group of squares or a group of circles, depending on the data passed to the column.

Aside from the shape of the graphics, these two groups are identical, and both reside in the Row Template in the correct column's group. Each group also contains an "Add" button, so I can dynamically interact with the group and add another shape into that cell by updating the internal data. The graphics can also be deleted, shifting all subsequent graphics' locations to retain the visual integrity I am aiming for.

Because I want the two groups' behaviors to be exactly identical, I have been writing my Behavior Script handlers with a switch statement that essentially just interacts with the objects of the correct group, based on the case (either Square or Circle).
Simple example: **Note: this code is not where my problem lies; I am merely including it in an attempt to clarify my methodology in this DG.**

Code: Select all

on MouseUp
   put the short name of the target into tTarget
   switch tTarget
      case "Circle"
      put the cCircleGroupCustomProperty into tCounter
      break
   case "Square"
      put the cSquareGroupCustomProperty into tCounter
      break
   end switch

   DoStuff tCounter
end MouseUp
However, my LayoutControl handler works perfectly every time for the Circle group, and not for the Square group. I have made sure everything is identical, with the only differences being the name of the objects that the scripts interact with (i.e. grc "Square 2" of grp "Squares" of me instead of grc "Circle 2" of grp "Circles" of me).

I believe the problem has something to do with a procedure the datagrid does to "prime" itself or something... Namely, when I populate a single row of the DG, my LayoutControl script executes ~10 times (until the entire visible portion of the DG is filled with the same initial-state layout). Then, it executes FillInData, finds that there is only one populated line, and suddenly all of the successive lines show empty, like they should.

This is normally fine, but I have noticed that this "initial state" always uses the "Circles" group and not the "Squares" group, even when I have set the visible of the former to false and the latter to true in FillInData (in the cases where I want to populate the cell with squares).

So help me understand: What does the DG do by default? Is LayoutControl supposed to be called recursively before FillInData is called to see if there even should be data displayed?

Hopefully someone can help!

Thanks a million!
Phil E.
Last edited by Gage on Sun Aug 17, 2014 12:37 pm, edited 2 times in total.

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

Re: Datagrid Table LayoutControl Issue

Post by Klaus » Sun Aug 17, 2014 12:14 pm

Hi Phil,

not sure I understand your problem, never worked with "layoutcontrol",
but your script does not look like it will work as exspected!

the target -> will give something like this:
button "a button"
field "a locked field"
etc.

...
put the target into tTarget
switch tTarget
case "Circle"
## See above: tTarget is NEVER "Circle" or "Square"
...

You could check:
the short name of the target
the short name of the owner of the target


Best

Klaus

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Datagrid Table LayoutControl Issue

Post by Gage » Sun Aug 17, 2014 12:22 pm

Klaus,

:shock: ?! How have you never used LayoutControl? It's the built-in DG handler for positioning stuff! :shock:

And, oops, yes it actually says the short name of the target in my script, not the target. You're totally right. I was just burning through the example to show my method for creating 2 separate, but essentially identical behaviors, differentiated only by graphic names.

Is there anything I can clarify in specific? I was trying to convey what is to me a vague, hard-to-pin-down problem, while not diving into an explanation that looks like a doctorate dissertation :D

Best,
Phil E.

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

Re: Datagrid Table LayoutControl Issue

Post by Klaus » Sun Aug 17, 2014 12:31 pm

Hi Phil,
Gage wrote: :shock: ?! How have you never used LayoutControl? It's the built-in DG handler for positioning stuff! :shock:
well, I never had the need for this, so please get over it! :D
Gage wrote:Is there anything I can clarify in specific?
No, sorry, have to pass this to someone else...


Best

Klaus

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Datagrid Table LayoutControl Issue

Post by Gage » Sun Aug 17, 2014 12:33 pm

Do you use some other method, or just not use datagrids? Cause I would love to not be using the LayoutControl right now, since I evidently don't know how it works or when it is called.

Phil

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Datagrid Table LayoutControl Issue

Post by bn » Sun Aug 17, 2014 12:35 pm

Hi Phil,

I don't understand your use of the short name of the target and then switch tTarget.

As you explain your grc "Circle 2" would return as short name "Circle 2".

That is not meeting the switch condition

Code: Select all

case "Circle"
if you always have a space between "circle" / "Square" and the number then you could say

Code: Select all

switch word 1 of the short name of the target
maybe that is the reason why it does not work. I would have to assume that you have at least one graphic that is just named "circle".

I am a little confused.

It is better you post some real code and not some explanatory code when debugging


Kind regards
Bernd

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Datagrid Table LayoutControl Issue

Post by Gage » Sun Aug 17, 2014 12:50 pm

Hi Bernd,

Yes, those are two separate examples. Neither of which is actually my problem. I'm sure all of the naming protocols I have coded finally work, after hours of debugging resulting in 100% expected results in the case where I use the Circles group.

In a similar fashion to the example code I included, I have duplicated the script from the Circles case for the Squares case, and since my Square objects are named with the same convention, it would also work correctly.

HOWEVER (here's my problem), something odd is happening within the Datagrid itself... I am mainly trying to learn about the Behavior Script's function. Which is called first: FillInData or LayoutControl? <-- I set the vis of my chosen group in FillInData, then use whichever group is visible in the LayoutControl script to position that (ignoring the group that is invisible, since I am not using it). However, sometimes I see LayoutControl get called first, then repeat without ever going to FillInData.

There is a whole cycle that seems to happen where PRIOR to FillInData ever being called, LayoutControl is called iteratively until all of the visible rows of the DG get populated. Then FillInData is called, and only the visible rows WITH DATA stick around; the others disappear. This is fine, however, I don't get the opportunity to set the visible of the group I want, so LayoutControl only lays out the Circles group, which is a sort of default.

I hope I am making more sense, even though that was lengthy. I can dump hundreds of lines of code on here if it would help, but I think my problem lies in my interpretation of the way and the order that LayoutControl and FillInData are called.

Thanks so much for the attention!

All the best,
Phil E.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Datagrid Table LayoutControl Issue

Post by bn » Sun Aug 17, 2014 1:34 pm

Hi Phil,

I think there is probably one person that can answer this
Zryip TheSlug,
he makes the fantastic tool DatagGridHelper which is worth every penny it costs. He has a subforum here. He is a very kind person and if you explain your problem you might get an answer, even if it is not DataGridHelper related.
http://forums.livecode.com/viewforum.php?f=78

there is a trial version for Data Grid Helper
http://forums.livecode.com/viewtopic.php?f=78&t=20571

It seems that he is one of the very few (besides Trevor DeVore who made the datagrid) that have understood the dataGrid completely.

Kind regards
Bernd

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

Re: Datagrid Table LayoutControl Issue

Post by sritcp » Sun Aug 17, 2014 7:22 pm

Hi Phil:
There is a whole cycle that seems to happen where PRIOR to FillInData ever being called,.........
Yes, there appears to be some pre-processing that goes on before actual data is filled in. The fields are laid out but left blank, but if a column has a button (for example) then the default state of the button is used to populate all the visible rows of the DataGrid (i.e., an option button would show "Choice 1" on all rows). It is possible that your column template has a circle (as the placeholder) so it is used to pre-populate the data grid.
However, my LayoutControl handler works perfectly every time for the Circle group, and not for the Square group. I have made sure everything is identical, ........
In your "Switch" control structure, if you were to exchange the places of circle and square (so that square is the first case), I'd expect the whole situation to reverse, i.e., squares appear, but not circles. Did you try that and see?
If that is true, then it is possible that your FillinData for that column isn't doing anything, and whatever you see is due to the pre-filling.
You can then debug this, by placing

Code: Select all

put the dgLine of me after msg
in each of the switch branches.
You can also try if-then-else control structure as a variant.

Regards,
Sri

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Datagrid Table LayoutControl Issue

Post by Gage » Sun Aug 17, 2014 8:48 pm

Bernd,

I have a licensed copy of DGH, and you're right; it is fantastic! Thank you for giving me that link and referring me to one of the masters! :D


Sri,

It seems like you understand very well what I am trying to communicate; thank you for taking the time to look into this!

I will go ahead and take your suggestions, in order to see what changes trigger the Square to become the default state. My hope is that the pre-processing cycle does not set some properties in my Template that negate the possibility of having two functioning sets of possible controls to display.

I'm not yet sure I understand the dgLine debugging methodology, but I will look further into it in a few minutes when I get there. I'm sure it will become clear upon further investigation.

Thank you both for your helpful responses!

Kind regards,
Phil E.

Post Reply