Page 1 of 1

Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 6:55 am
by francis6425
Hi,

I have a datagrid with multiple image field inside the row template.
I need to loop thru all the image controls of the hilited row of the datagrid.
Can any expert please show me how to do it.

Regards,
Francis

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 6:57 am
by francis6425
Sorry, I forget to mention that I need to loop thru all the image control inside the hilited row in the on mouseUp event.

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 12:03 pm
by Klaus
Hi Francis,

1. welcome to the forum! :D

2. Please stick to the correct Livecode terms to get precise help!
"multiple image field"? image <> (TEXT) field
Sorry, no idea what you are trying to do?


Best

Klaus

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 12:55 pm
by zaxos
Assuming the name of the image controls are image1-5:

Code: Select all

on mouseUp
local theLine,theData
put the dgHilitedLines of group "myDataGrid" into theLine
put the dgDataOfLine[theLine] of group "myDataGrid" into theData
repeat for each element tImage in theData
local x
add 1 to x
set the text of img "previewImage" to tImage["image"&x] -- or whatever else you need to do with it
end repeat
end mouseUp
Klaus is right by the way, a field control is different from an image control, guess you mixed them up :p

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 2:08 pm
by francis6425
Hi,

Sorry. I mean image control.
Basically in my row template, I have 3 image control.
when there is a mouse click directly on the visible non-transparent portion of the image, i can detect it.
But unable to detect when there is a mouse click on the transparent portion of the image. I understand this is the correct behaviour but hope to bypass this limitation.
So what I'm trying to do is to get loop thru all 3 image control and check if the mouseloc is within any of the rect of these image control in the hilited row.

I also can't replace the image control with a button control as the images are reference to image files in a folder.

Regards,
Francis

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 2:33 pm
by Klaus
Hi Francis,

in that case, I would put an opaque graphic behind each image, with the same "rect" as the image!
Then I would give them clever names so I can see if a "clicked" graphic actually "belongs" to a specific image.
Know what I mean?


Best

Klaus

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 3:14 pm
by francis6425
Hi Klaus,

Other than putting an opaque image behind, is there any way of looping thru the image control of the hilited row?

Regards,
Francis

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 3:17 pm
by zaxos
Not sure if i understood wrong but isnt this what you'r looking for?
-- this script inside the card

Code: Select all

on mouseUp
if the mouseLoc is whithin the rect of "image1" then -- or whatever if not image1
-- do something
else if the mouseLoc is whithin the rect of "image2" then
-- do something
else if the mouseLoc is whithin the rect of "image3" then 
-- do something
end if
pass mouseUp
end mouseUp

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 3:43 pm
by francis6425
Hi Zaxos,

There will be multiple rows inside the datagrid with the same image name (same name as inside the row template, only the id will be different for each row)
For my case, I need to loop thru only the image control of the hilited row.

Regards,
Francis

Re: Get list of controls of hilited row of datagrid

Posted: Tue Aug 18, 2015 5:51 pm
by zaxos
Maybe this helps:

Code: Select all

on getData
   put the dgHilitedIndex of grp "sampleForm" into theIndex
   put the dgDataControlOfIndex [theIndex] of grp "sampleForm" into tControl
   put the name of tControl into tOwner
   repeat with x = 1 to the number of controls
      if the owner of control x is tOwner then
         put the long ID of control x&return after tControls
         -- or put "control"&&x&return after tControls if what you need is the control number
         -- or put the name of control x&return after tControls
      end if
   end repeat
delete last char in tControls
end getData
And after that:

Code: Select all

on mouseUp
getData
repeat for each line tControl in tControls
if the mouseLoc is within the rect of tControl then
put tControl
end if
pass mouseUp
end mouseUp
I tryed the first code and it returns only the controls of the hillited line. Guess thats what you wanted, wish you the best.