Page 1 of 1

Passing DataGrid Row Number to card

Posted: Thu May 23, 2013 4:39 pm
by steveharman
Hi,

This is my first exposure to LiveCode and so far I'm loving it.

I've managed to do the leg-work with my app, bring in data from a webservice, convert JSON to an LC array and map it to a DataGrid just fine - much easier than expected. What I now need to do is to be able to click on a row in my DataGrid and pass the row number on to a new card - where it can be used as an array reference to retrieve the correct values for the chosen record (row) in the previous card's DataGrid.

All the reading I've done explains how to do really impressive things with the DataGrids but not the very simple thing that I'm trying to achieve. I've even understood how to send variables as messages between cards, but not on how to extract the DataGrid's row number when clicked and pass that as the variable. Can anyone give me a tip or link to an article showing what to do?

Many thanks,

Steve

Re: Passing DataGrid Row Number to card

Posted: Thu May 23, 2013 4:58 pm
by Klaus
Hi Steve,

there are many ways to do so :-)

I would use a custom property of the stack or card or whatever and set it
each time the user selects a row from the datagrid with a "selectionchanged" handler
in the script of the datagrid group like this:

Code: Select all

on selectionChanged pHilitedIndex, pPrevHilitedIndex
  ## This message comes with 2 parameters 
  ## and I think their names a quite selfexplaining :-)
 
   ## Store current index in a CP of the stack:
   set the cCurrentIndex of this stack to pHilitedIndex
end selectionChanged
Done, now you can access this "row" number in any script:

Code: Select all

...
put the the cCurrentIndex of this stack into tCurrentIndex
if tCurrentIndex = EMPTY then
    ## maybe not yet initialized?
    ## ERROR CHECKING ERROR CHECKING ERROR CHECKING ERROR CHECKING :-D
    put 1 into tCurrentIndex
end if
## Now do something with tCurrentIndex...
...

Best

Klaus

Re: Passing DataGrid Row Number to card

Posted: Fri May 24, 2013 10:30 am
by steveharman
Hi Klaus,

Many thanks for the reply - you've saved me many hours! :-)

Regards,

Steve