如何在LiveCode DataGrid中创建扩展字段编辑器?

时间:2013-03-07 03:40:39

标签: datagrid livecode

我需要在LiveCode DataGrid中创建一个字段编辑器,该字符编辑器会随着用户类型的增长而增长,以适应字段的formattedHeight。其余的基础行控件也需要调整大小,同时将任何后续行控件向下移动。

2 个答案:

答案 0 :(得分:4)

回答我自己的问题,因为它可能对其他人有用。

将字段编辑器行为按钮从revDataGridLibrary堆栈复制到其上带有行模板的卡片。

编辑要编辑的字段的脚本,如下所示(请注意,您需要将行为按钮引用修复为新字段edtior行为的长ID):

on preOpenFieldEditor pEditor
   set the behavior of pEditor to the long id of button id 1023 of card id 1010 of stack "Data Grid Templates 1362091650635"
   set the uRowControl of pEditor to the long id of the owner of me
end preOpenFieldEditor

编辑字段编辑器行为脚本,添加以下内容:

local sHeight,sRowControl

setProp uRowControl pRowControl
   put pRowControl into sRowControl
end uRowControl

on openField
   put the formattedHeight of me into sHeight
   pass openField
end openField

on textChanged
   local tHeight,tRect
   lock screen
   put the formattedHeight of me into tHeight
   if sHeight <> tHeight then
      put the rect of me into tRect
      put item 2 of tRect+ tHeight into item 4 of tRect
      set the rect of me to tRect
      put tHeight into sHeight
      dispatch "UpdateRow" to sRowControl with the long id of me
   end if 
   unlock screen
   pass textChanged
end textChanged

现在编辑行模板行为,添加以下处理程序(请注意,在这种情况下,正在编辑的字段名为“note”,因此您需要更改用例):

on UpdateRow pFieldEditor
   set the rect of graphic "Background" of me to the rect of pFieldEditor
   set the rect of fld "note" of me to the rect of pFieldEditor
   set the rect of me to the formattedRect of me
   put the uScriptLocal["sTableObjectsA"] of me into tTableObjectsA
   repeat for each line tControl in tTableObjectsA["all row controls"]
      delete word -2 to -1 of tControl -- of me
      put tControl into tControlA[the dgIndex of tControl]
   end repeat
   put the bottomLeft of me into tTopLeft
   repeat for each item tIndex in tTableObjectsA["current"]["indexes"]
      if tIndex > the dgIndex of me then
         set the topLeft of tControlA[tIndex] to tTopLeft
         put the bottomLeft of tControlA[tIndex] into tTopLeft
      end if
   end repeat
end UpdateRow

答案 1 :(得分:0)

看起来很有用,Monte。问题:为什么preOpenField处理程序?这个信息不能在设计时设置一次吗?每次调用编辑器时DataGrid都会创建一个新的字段控件吗?