Get list of controls of hilited row of 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

Post Reply
francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Get list of controls of hilited row of datagrid

Post by francis6425 » Tue Aug 18, 2015 6:55 am

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

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Get list of controls of hilited row of datagrid

Post by francis6425 » Tue Aug 18, 2015 6:57 am

Sorry, I forget to mention that I need to loop thru all the image control inside the hilited row in the on mouseUp event.

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

Re: Get list of controls of hilited row of datagrid

Post by Klaus » Tue Aug 18, 2015 12:03 pm

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

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Get list of controls of hilited row of datagrid

Post by zaxos » Tue Aug 18, 2015 12:55 pm

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
Knowledge is meant to be shared.

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Get list of controls of hilited row of datagrid

Post by francis6425 » Tue Aug 18, 2015 2:08 pm

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

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

Re: Get list of controls of hilited row of datagrid

Post by Klaus » Tue Aug 18, 2015 2:33 pm

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

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Get list of controls of hilited row of datagrid

Post by francis6425 » Tue Aug 18, 2015 3:14 pm

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

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Get list of controls of hilited row of datagrid

Post by zaxos » Tue Aug 18, 2015 3:17 pm

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
Knowledge is meant to be shared.

francis6425
Posts: 15
Joined: Tue Aug 18, 2015 6:48 am

Re: Get list of controls of hilited row of datagrid

Post by francis6425 » Tue Aug 18, 2015 3:43 pm

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

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Get list of controls of hilited row of datagrid

Post by zaxos » Tue Aug 18, 2015 5:51 pm

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.
Knowledge is meant to be shared.

Post Reply