Tooltips in the Datagrid

Bob Sneidar bobsneidar at iotecdigital.com
Fri Nov 10 18:19:34 EST 2017


Okay forget everything before. Put THIS in your datagrid script:

on mouseEnter
   lock messages
   wait 30 ticks
   unlock messages
   put the long id of me into tMyID
   put wordOffset("card", tMyID) into tFirstWord
   put word tFirstWord to -1 of tMyID into tThisCard
   put word 2 of the mouseControl into tControlNum
   if tControlNum is not a number then exit mouseEnter
   put the name of control tControlNum into tControlName
   if word 1 of tControlName is not "field" then exit mouseEnter
   put the long id of control tControlNum of tThisCard into tTarget
   put <list of column names> into tKeyList
   dgToolTip tTarget, tKeyList
end mouseEnter

on mouseLeave
   set the tooltip of the target to empty
end mouseLeave

Then THIS in a backscript:

on dgToolTip tTarget, tKeyList
   --    if the optionKey is up then
   --       set the tooltip of tTarget to empty
   --    exit dgToolTip
   --   end if
   put the dgIndex of the dgDataControl of tTarget into tIndex -- Thanks Trevor!!
   replace quote with empty in tTargetName
   put the last word of tTargetName into tLine
   put the dgDataOfIndex [tIndex] of tTarget into aLineData
   
   if tKeyList is empty or the shiftKey is down then
      put the keys of aLineData into tKeyList
      sort lines of tKeyList ascending
      replace cr with comma in tKeyList
   end if
   
   set the numberformat to "0000"
   
   repeat for each item tKey in tKeyList
      add 1 to tCounter
      put "field " & tCounter into tFieldName
      put aLineData [tKey] into aRecordData [tCounter & ". " & tKey]
   end repeat
   
   put arrayToText(aRecordData, "record") into tText
   sort lines of tText numeric ascending by word 1 of each
   
   set the tooltip of tTarget to tText
end dgToolTip

function arrayToText aArrayData, pFormat, pStripRecordKeys
   if aArrayData is not an array then
      put "ERROR: Data passed is not an array!" into theValue
      return theValue
   end if
   
   if pStripRecordKeys is not in "true|false" then put false into pStripRecordKeys
   -- sort tArrayKeys ascending
   
   -- may be an array of values
   put the keys of aArrayData into tArrayKeys
   sort lines of tArrayKeys numeric ascending
   put line 1 of tArrayKeys is 0 into tHasHeader
   
   -- convert single array to numeric array of arrays
   if line 1 of tArrayKeys is not a number then
      put aArrayData into aTempArray [1]
      put aTempArray into aArrayData
      put the keys of aArrayData into tArrayKeys
   end if
   
   switch pFormat
      case "record"
         repeat for each line tArrayKey in tArrayKeys
            put aArrayData [tArrayKey] into aArrayRecord
            put the keys of aArrayRecord into tColumnKeys
            
            repeat for each line tColumnKey in tColumnKeys
               put tColumnKey & ": " & aArrayRecord [tColumnKey] & cr after tValue
            end repeat
         end repeat
         break
      case "table"
         -- table header
         if not tHasHeader then put cr into tValue
         
         repeat for each line tArrayKey in tArrayKeys
            add 1 to tCount
            put aArrayData [tArrayKey] into aArrayRecord
            put the keys of aArrayRecord into tColumnKeys
            sort lines of tColumnKeys numeric ascending
            
            repeat for each line tColumnKey in tColumnKeys
               if pStripRecordKeys and (char 1 of tColumnKey is "@") then next repeat
               
               if tCount = 1 and not tHasHeader then put tColumnKey & tab after line 1 of tValue
               put aArrayRecord [tColumnKey] & tab after tValue
            end repeat
            
            put cr into last char of tValue
         end repeat
         break
   end switch
   
   return tValue
end arrayToText





More information about the use-livecode mailing list