Page 1 of 1

DataGrid: Scripting mouse click in a cell

Posted: Tue Jul 15, 2014 6:21 pm
by sritcp
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.

Re: DataGrid: Scripting mouse click in a cell

Posted: Tue Jul 15, 2014 10:51 pm
by Zryip TheSlug
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,

Re: DataGrid: Scripting mouse click in a cell

Posted: Thu Jul 17, 2014 10:42 pm
by sritcp
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.