Help targeting row in data grid

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
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Help targeting row in data grid

Post by doobox » Wed Jul 11, 2012 12:47 am

Hi there,

Best way to explain this is show where i am at at the moment :

Code: Select all

on mouseUp
   put the dgProps["Row Template"] of group "DataGrid 1" into theRowTemplate
   set the visible of img "redlight" of theRowTemplate to true
   dispatch "ResetList" to group "DataGrid 1"
end mouseUp
That is on a button outside the data grid, and almost doing what i need.
But this shows the red light on every row in the grid (form).

I want to target just individual rows in the grid, and show the red light on a row i target.. like:

Code: Select all

on mouseUp
   put the dgProps["Row Template"] of (DgLINE[2]) of group "DataGrid 1" into theRowIAmTargeting
   set the visible of img "redlight" of theRowIAmTargeting to true
   dispatch "ResetList" to group "DataGrid 1"
end mouseUp
Just want to narrow the target to a row in the template in some way like that.
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Help targeting row in data grid

Post by doobox » Wed Jul 11, 2012 8:04 am

I figured this out....

Add to the behavior script, fillInData handler

Code: Select all

   if (pDataArray["show red light"] is "show") then
      set the visible of image "greenlight" of me to false
      set the visible of image "redlight" of me to true
   else
      set the visible of image "greenlight" of me to true
      set the visible of image "redlight" of me to false
   end if
Then i run this in my card handler.. this is inside a repeat loop that has x declared as a number that will equate to the corresponding index if the data grid..

Code: Select all

if tRedLight then
         put the dgDataOfLine[x] of group "DataGrid 1" into theDataA
         put "show" into theDataA["show red light"]
         set the dgDataOfLine[x] of group "DataGrid 1" to theDataA
else
        put the dgDataOfLine[x] of group "DataGrid 1" into theDataA
         put "hide" into theDataA["show red light"]
         set the dgDataOfLine[x] of group "DataGrid 1" to theDataA
end if
Kind Regards
Gary

https://www.doobox.co.uk

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

Re: Help targeting row in data grid

Post by Klaus » Wed Jul 11, 2012 2:46 pm

Hi Gary,

great you figured this out by yourself!

Yes "the row template" is of course the template for ALL rows, so hiding 1 object
in that template will affect ALL rows.

DataGrids a very powerful, but yet very hard to master 8)
I am still using the docs everytime I work with DGs.


Best

Klaus

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

Re: Help targeting row in data grid

Post by Klaus » Wed Jul 11, 2012 2:55 pm

Hi Gary,

here some hints to make your scripts a bit shorter :D

Code: Select all

...
## Put only that into the "IF THEN" clause that belongs there: 
put the dgDataOfLine[x] of group "DataGrid 1" into theDataA
if tRedLight then        
    put "show" into theDataA["show red light"]
else
    put "hide" into theDataA["show red light"]
end if
set the dgDataOfLine[x] of group "DataGrid 1" to theDataA
...
:D

If you can get friend with Monsieur Boole (the TRUE/FALSE guy :D ):

Code: Select all

...
## No more if then, but some logics:
put (pDataArray["show red light"] = "show") into isRed

## Consider the two possible values and try to understand the following two lines:
set the visible of image "redlight" of me to isRed
set the visible of image "greenlight" of me to NOT isRed
...
NOT true = false
NOT false = true


Best

Klaus

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Help targeting row in data grid

Post by doobox » Wed Jul 11, 2012 2:56 pm

Tell me about it Klaus :-)

I thought i had them licked the last time i built an app that used a data grid.

Come back a few months later for this project, and you'd swear i'd never used livecode before :-)

Thanks for streamlining the code..!
Kind Regards
Gary

https://www.doobox.co.uk

Post Reply