Get content of DataGrid row with mouse double-click

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
gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Get content of DataGrid row with mouse double-click

Post by gilar » Mon Sep 10, 2018 4:14 am

Hi Everybody

Is it impossible to get content of row from a DataGrid table with mouse double-click?
(It's mean while weare double clicking the row)
And is it impossible too to change of highlighted color?

Comment and help would be appreciate



Best Regards

Gilar Kadarsah
Gilar | from INDONESIA

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

Re: Get content of DataGrid row with mouse double-click

Post by ghettocottage » Mon Sep 10, 2018 5:25 am

Here is a function for getting the info of whatever row is selected on a dataGrid that has a list of clients. The function uses that info to fill out a form with various fields:

Code: Select all


/*********************************************************
select function --selecting a client from the datagrid
**********************************************************/
on selectClient
   --get the number of the highlited row
   put the dgHilitedLines of grp "data" into tLine
   --get the data of that line into an array
   put the dgDataOfLine[tLine] of group "data" into tSelected
   
   --check if there is an id for the row clicked
   if tSelected[id] is a number then
      
      --pull whatever data you want out of that array
      put tSelected[id]  into fld "id"
      put tSelected[name]  into fld "name"
      put tSelected[email]  into fld "email"
      put tSelected[city]  into fld "city"
      put tSelected[state]  into fld "state"
      put tSelected[zip]  into fld "zip"
      put tSelected[phone1]  into fld "phone1"
      put tSelected[phone2]  into fld "phone2"
      put tSelected[company]  into fld "company"
      put tSelected[taddress]  into fld "address"

      highLightButtons  tCard, tList
      
   else
      clearClient
   end if
   
end selectClient

You can then use that function however you want, for example, on the dataGrid, edit the script like:

Code: Select all

on mouseUp
   selectClient
end mouseUp

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Get content of DataGrid row with mouse double-click

Post by gilar » Mon Sep 10, 2018 1:02 pm

Hi ghettocottage .... thanks for replay

I put this code into my table script and i create
some text field (No._fld, Name_fld, Laps_fld, Col5_fld)

but there is nothing happen, any advice?

Code: Select all

on mouseDoubleUp
   //put the dgHilitedLines of group "riders_tbl"  into theLine
   selectClient
end mouseDoubleUp


/*********************************************************
select function --selecting a client from the datagrid
**********************************************************/
on selectClient
   --get the number of the highlited row
   put the dgHilitedLines of grp "riders_tbl" into tLine
   --get the data of that line into an array
   put the dgDataOfLine[tLine] of group "riders_tbl" into tSelected
   
   --check if there is an id for the row clicked
   if tSelected[id] is a number then
      
      --pull whatever data you want out of that array
      put tSelected[No.]  into fld "No._fld"
      put tSelected[Name]  into fld "Name_fld"
      put tSelected[Laps]  into fld "Laps_fld"
      put tSelected[Col5]  into fld "Col5_fld"
      
      
      highLightButtons  tCard, tList
      
   else
     clearClient
   end if
   
end selectClient
Gilar | from INDONESIA

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Get content of DataGrid row with mouse double-click

Post by Klaus » Mon Sep 10, 2018 1:26 pm

Hi friends,

non-numeric keys of arrays need to be in QUOTES unless we use a VARIABLE with that name for the key!
If not, I may produce unwanted results.

Code: Select all

...
put tSelected["id"]...
...
put tSelected["No."]  into fld "No._fld"
put tSelected["Name"]  into fld "Name_fld"
put tSelected["Laps"]  into fld "Laps_fld"
put tSelected["Col5"]  into fld "Col5_fld"
...
And where did you put that MOUSEUP handler?
A separate button?

Best

Klaus

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Get content of DataGrid row with mouse double-click

Post by gilar » Mon Sep 10, 2018 2:29 pm

I try delete some line of the code and it is work

Code: Select all

on mouseDoubleUp
   selectClient
end mouseDoubleUp
on selectClient
      put the dgHilitedLines of grp "riders_tbl" into tLine
      put the dgDataOfLine[tLine] of group "riders_tbl" into tSelected
      put tSelected["No."]  into fld "No._fld"
      put tSelected["Name"]  into fld "Name_fld"
      put tSelected["Laps"]  into fld "Laps_fld"
      put tSelected["Col_5"]  into fld "Col5_fld"
end selectClient

delete this

Code: Select all

   --check if there is an id for the row clicked
   if tSelected[id] is a number then
 
and this

Code: Select all

      
      highLightButtons  tCard, tList
      
   else
     clearClient
   end if
   
Now I try to change highlight color when mouse double click



Thanks
Gilar | from INDONESIA

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Get content of DataGrid row with mouse double-click

Post by gilar » Mon Sep 10, 2018 2:32 pm

Hi again Klaus .... :)
Klaus wrote:
Mon Sep 10, 2018 1:26 pm

Code: Select all

...
put tSelected["id"]...
...
put tSelected["No."]  into fld "No._fld"
put tSelected["Name"]  into fld "Name_fld"
put tSelected["Laps"]  into fld "Laps_fld"
put tSelected["Col5"]  into fld "Col5_fld"
...
Still got an error, after I delete some line of the script finally success
And where did you put that MOUSEUP handler?
A separate button?
No. I put it on DataGrig


Best Regards


Gilar
Gilar | from INDONESIA

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

Re: Get content of DataGrid row with mouse double-click

Post by ghettocottage » Mon Sep 10, 2018 3:34 pm

Code: Select all

   --check if there is an id for the row clicked
   if tSelected[id] is a number then
I should have removed that before posting. It is check I have in place to test if a new record is being created.

Out of curiousity, does your highlighted row change color at all? I think mine changes to a bright blue color when selected. I do not remember doing anything to make that happen (default behavior I think)

gilar
Posts: 96
Joined: Sat Sep 26, 2015 12:59 pm

Re: Get content of DataGrid row with mouse double-click

Post by gilar » Mon Sep 10, 2018 4:40 pm

Finally i can make it with this code

Code: Select all

on mouseDoubleUp
   //put the dgHilitedLines of group "riders_tbl"  into theLine
   selectClient
end mouseDoubleUp


on selectClient
      if the dgprop["hilite color"] of group "riders_tbl" is "0, 255, 255" then
         set the dgprop["hilite color"] of group "riders_tbl" to "255, 0, 0"
         --get the number of the highlited row
         put the dgHilitedLines of grp "riders_tbl" into tLine
         --get the data of that line into an array
         put the dgDataOfLine[tLine] of group "riders_tbl" into tSelected
         
         --check if there is an id for the row clicked
         //if tSelected["id"] is a number then
         
         --pull whatever data you want out of that array
         put tSelected["No."]  into fld "No._fld"
         put tSelected["Name"]  into fld "Name_fld"
         put tSelected["Laps"]  into fld "Laps_fld"
         put tSelected["Col_5"]  into fld "Col5_fld"
         
      else
         set the dgprop["hilite color"] of group "riders_tbl" to "0, 255, 255"
      end if
      //highLightButtons  tCard, tList
      
      //else
      //clearClient
      //end if
      
   end selectClient
Thank you ghettocottage and Klaus for the Advice
God bless you all



Best Regards

Gilar Kadarsah
Gilar | from INDONESIA

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”