Datagrid loc field dynamically

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: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
link76
Posts: 76
Joined: Fri Nov 04, 2011 1:52 pm

Datagrid loc field dynamically

Post by link76 » Thu Feb 22, 2018 2:46 pm

Hello,

I would like to set the position of a label dynamically in my datagrid template,

I tried this way but it works only for the first 2 lines.

behavior script:

Code: Select all

  if the number of chars of pDataArray["A_B"] = 1 then
      set the loc of field "E_B" of this card of me to 724,10
      set the text of field "E_B" of me to pDataArray["A_B"]
   else
      set the loc of field "E_B" of this card of me to 722,10
      set the text of field "E_B" of me to pDataArray["A_B"]
   end if
thank you

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

Re: Datagrid loc field dynamically

Post by Klaus » Thu Feb 22, 2018 2:58 pm

"of this card" or "of me"? I don't think you can have both.
But since this is the datagrid behavior script, I would propose "of me".

However the fields are part of the datagrids "grouped grouped groups", so I doubt this will work at all.

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

Re: Datagrid loc field dynamically

Post by dunbarx » Thu Feb 22, 2018 4:50 pm

What Klaus said.

Most importantly, you really ought not to relocate a field already part and parcel of the DG groupGroupGroup. This can, certainly, be done:

Code: Select all

set the loc of fld "col 1 0002" to "50,50"
But I cannot think of any good reason to. I am posting just to make sure you understand how the parts of a DG go together.

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6154
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Datagrid loc field dynamically

Post by FourthWorld » Thu Feb 22, 2018 5:51 pm

The "of me" clause is the way to go. Adding the extra card reference makes it invalid.

If "me" contains:

Code: Select all

group id 2001 of card id 1001 of stack "SomeStack"
...then prepending the object and card reference as shown above would give us this evaluation:

Code: Select all

field "E_B" of card id 1001 of stack "SomeStack" of group id 2001 of card id 1001 of stack "SomeStack"
That will of course generate an "object not found" error.

In general, when constructing object references the expected order is small to large, so putting a card reference before a control reference won't work under any circumstances.

Using "me", "the target", and other functions that return complete object references, there's no need to add anything at all to resolve that object. Here "me" refers to a group, so it will include the card reference as part of its complete descriptor.

So to refer to an object within a group, and given that a complete reference to the group object is already contained in "me", this will be what you'd need:

Code: Select all

field "E_B" of me
Setting the location is a second issue here. LC uses absolute coordinates, starting at the upper-left of the card. Being absolute, any DG row group setting one of its controls to a specific absolute location will mean that all rows will be rendered with that control in each of them rendered at the same place on the card. Probably not what you want.

If you want a control within a row group to be placed relative to the row group, you can use something like:

Code: Select all

set the loc of field "E_B" of me to (the left of me + 724),(the top of me + 10)
That will place the center of the field 724 pixels to the left of each row group, and 10 pixels below the top of each row group.

And I'm guessing from those coordinates that perhaps rather than "location" (which is the object's center) you may have meant "topLeft". If so, "topLeft" (or "topRight", "bottomLeft", and "bottomRight" where needed) can be used:

Code: Select all

set the topLeft of field "E_B" of me to (the left of me + 724),(the top of me + 10)
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”