DataGrid: Scripting mouse click in a cell

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
sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

DataGrid: Scripting mouse click in a cell

Post by sritcp » Tue Jul 15, 2014 6:21 pm

One of the columns is my DataGrid is called "Notes". The user can type in (a variable amount of) text in that cell. The width of the "Notes" column being narrow, the DataGrid cannot display the contents of the Note (except for the first word or two). It would be nice to have the contents of the cell displayed in a separate field when the user clicks in a cell in the "Notes" column.

I see that double-clicking a cell opens it for editing. Thus, I infer that a cell does recognize a mouse click. So, how/where do I script a single click?

Thanks for any help,
Sri.

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: DataGrid: Scripting mouse click in a cell

Post by Zryip TheSlug » Tue Jul 15, 2014 10:51 pm

Sri,

A possible solution is to add a mouseUp handler in the datagrid group script:

Code: Select all

on mouseUp
   if (the dgColumn of the dgDataControl of the target is "Notes") then
      doSomething
   end if
end mouseUp
doSomething will only be executed if one clickes on a cell into the "Notes" column. Be sure to have data in the row to have something happening.


By anticipation, you will probably have the need to get the cell's content for displaying the corresponding text to update:

Code: Select all

on mouseUp
   local tTheIndex
   
   if (the dgColumn of the dgDataControl of the target is "Notes") then
      put the dgIndex of the target into tTheIndex
      set the text of fld "myNotesEditor" to GetDataOfIndex(tTheIndex, "Notes")
      set the cIndex of fld "myNotesEditor" to tTheIndex
   end if
end mouseUp
Here, we are using the custom property cIndex for storing the index of the clicked row in the datagrid. So, when the user will update the field, we will able to update the corresponding "Notes" cell in the datagrid.

Here is a possible script for the field "myNotesEditor"

Code: Select all

on closeField
   dispatch "SetDataOfIndex" to grp "myDatagrid" with the cIndex of me, "Notes", the text of me
   dispatch "RefreshIndex" to grp "myDatagrid" with the cIndex of me

   pass closeField
end closeField
For more informations about the datagrid keywords (dgColumn, dgIndex, dgDataControl, GetDataOfIndex, SetDataOfIndex and RefreshIndex) have a look to the datagrid API:
http://lessons.runrev.com/m/datagrid/l/ ... a-grid-api


Best,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm
Location: Alexandria, Virginia

Re: DataGrid: Scripting mouse click in a cell

Post by sritcp » Thu Jul 17, 2014 10:42 pm

Hi TheSlug:

Thanks for the code. Works well!

I guess an alternative would be to edit the default column behavior of the specific column (here, "Notes") and add the following code:

Code: Select all

on mouseUp
put the text of me into field "myNotesEditor"
end mouseUp
Regards,
Sri.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”