DataGrid question...

Niggemann, Bernd Bernd.Niggemann at
Wed Apr 1 09:28:29 EDT 2020

This is a modification of Jaque's script to get the row and column of a locked tableField when the user clicks in a cell.

Use tableField whose lockText is true. Set its script to

on mouseUp
   put "Row:" && word 2 of the clickline into tRow
   put "Col:" && getColumn(the clickH) into tColumn
   set the itemDelimiter to tab
   put tRow &cr& tColumn & cr & "ClickH: " & the clickH into field "fRes"
end mouseUp

function getColumn pClickH
   put the tabstops of me into tTabs
   put the num of items in tTabs into tNumStops
   if tNumStops > 1 then
      put last item of tTabs - item -2 of tTabs into tTabWidth
      put item 1 of tTabs into tTabWidth
   end if
   set the itemdel to tab
   put the num of items in line 1 of me into tColumns
   if tNumStops < tColumns then -- add missing tabstops
      repeat with x = tNumStops+1 to tColumns
         put comma & (tTabWidth * x) after tTabs
      end repeat
   end if
   set the itemdel to comma
   put the hScroll of me into tHScroll
   put the borderwidth of me into tBrdr -- tested from 0 to 4
   put the leftMargin of me - 3 into tLeftMarg -- tested from 4 to 12
   put the left of me + tBrdr into tLeftAndBorder
   put tLeftAndBorder - tHScroll - tLeftMarg into tLeftOfItem
   put tLeftAndBorder - tHScroll + tLeftMarg + 1 into tRightOfItem -- + 1 is a fudge
   put 0 & comma before tTabs
   repeat with x = 1 to the num of items in tTabs
      if pClickH > (item x of tTabs) + tLeftOfItem and \
            pClickH < (item x+1 of tTabs) + tRightOfItem then
         return x
      end if
   end repeat
   return empty
end getColumn

In my testing it works for changed borderWidth and margins, hscrolls and vScrolls

If you want to test it take a regular field, set its name to "tf", set its script to above script

and from a button apply this

on mouseUp
   put "1,2,3,4,5,6" into tLine
   put empty into field "tf"
   replace comma with tab in tLine
   set the itemDelimiter to tab
   repeat 6
      put tLine & cr after tCollect
      repeat with i = 1 to 6
         add 6 to item i of tLine
      end repeat
   end repeat
   delete last char of tCollect
   lock screen
   put tCollect into field "tf"
   set the hGrid of field "tf" to true
   set the vGrid of field "tf" to true
   set the hScrollbar of field "tf" to true
   set the tabStops of field "tf" to 77
   set the lockText of field "tf" to true
   unlock screen
end mouseUp


Kind regards

More information about the use-livecode mailing list