Datagrid - Mouse up or selection change

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Datagrid - Mouse up or selection change

Post by Simon Knight » Mon Apr 28, 2014 11:38 am

Hi ,

I have a datagrid showing a list of records. The list is for viewing only and when the user selects a row I want to populate a number of fields and buttons with data from the selected row. I have created my own default column behavior based on the standard one. Into this I have added the following code :

Code: Select all

On MouseUp
   put the dgline of me  into tline -- counts down the list not sure how this relates to the data
   put the dgDataOfLine[tline] of me into tRecA
   DisplaySelectedRow tRecA
   pass MouseUp
end MouseUp
The code reads the line number of the row where the mouse up occurs then it reads the data from the row into an array variable. Next it calls the routine DisplaySelectedRow on the card and passes it the array of data. It all seems to work. However, given that I treat datagrids with the same caution I would give to a nest of vipers is my code o.k. or have I introduced an as yet undetected "feature" ? Is there a better way of achieving the same result ?

Simon K
best wishes
Skids

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

Re: Datagrid - Mouse up or selection change

Post by Klaus » Mon Apr 28, 2014 12:17 pm

Hi Simon,

I always use the "selectionchanged" message for this kind of stuff!

Advantage: this will also cover selections made with the ARROW keys!

Code: Select all

on selectionChanged pHilitedIndex, pPrevHilitedIndex
  put the dgDataOfLine[pHilitedIndex] of me into tRecA
  ## do your stuff here
  ## ...
end selectionChanged
Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Datagrid - Mouse up or selection change

Post by Simon Knight » Mon Apr 28, 2014 1:07 pm

Klaus,

Thanks, where does the handler go ?

Simon
best wishes
Skids

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

Re: Datagrid - Mouse up or selection change

Post by Klaus » Mon Apr 28, 2014 1:10 pm

Hi Simon,

that goes into the script of the datagrid GROUP (NOT the ROW behavior!)


Best

Klaus

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Datagrid - Mouse up or selection change

Post by Simon Knight » Mon Apr 28, 2014 1:12 pm

Klaus,

I found the lesson and now know its inside the group script.

Thanks again,

Simon
best wishes
Skids

Post Reply