DataGrid question...

J. Landman Gay jacque at
Mon Mar 30 15:42:20 EDT 2020

On 3/30/20 4:08 AM, Pi Digital via use-livecode wrote:
> So, have we all missed a clever and simple, non convoluted method of telling which cell in a scrollable, non editable table field has been clicked? Even if that cell is empty.

The table field is pretty rudimentary and so has limitations. For example, no messages are 
generated if a user clicks in a cell that is below the last text entry. Provided the field is 
full of data and user clicks on a populated cell, this seems to work:

on selectionChanged
   put "Row:" && word 2 of the clickline into tRow -- adjust for scroll here
   put "Col:" && getColumn(the clickH) into tColumn
   put tRow &cr& tColumn
end selectionChanged

function getColumn pClickH
   put the num of items in the tabstops of me into tNumStops
   put last item of the tabstops of me into tTabWidth -- in case we need to calculate it
   set the itemdel to tab
   put the num of items in line 1 of fld "tf" into tColumns
   if tNumStops < tColumns then -- add missing tabstops
     put the tabstops of me into tTabs
     repeat with x = tNumStops+1 to tColumns
       put comma & (tTabWidth * x) after tTabs
     end repeat
   end if
   set the itemdel to comma
   repeat with x = 1 to the num of items in tTabs
     if pClickH > item x of tTabs and pClickH < item x+1 of tTabs then
       return x
     end if
   end repeat
   return empty
end getColumn

This is as far as I got (I need to get back to work,) but I think all it's missing is 
calculating the row offset if the field is scrolled. David accounted for that.
Jacqueline Landman Gay         |     jacque at
HyperActive Software           |

More information about the use-livecode mailing list