我需要在 LiveCode DataGrid 中创建一个字段编辑器,该编辑器会随着用户类型的增长而增长以适应字段的 formattedHeight。底层行控件的其余部分也需要调整大小,同时向下移动任何后续行控件。
问问题
680 次
2 回答
4
回答我自己的问题,因为它可能对其他人有用。
将字段编辑器行为按钮从 revDataGridLibrary 堆栈复制到上面带有行模板的卡片。
编辑要编辑的字段的脚本,如下所示(请注意,您需要将行为按钮引用修复为新字段编辑行为的长 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
于 2013-03-07T03:40:38.650 回答
0
看起来很有用,蒙特。问题:为什么是 preOpenField 处理程序?该信息不能在设计时设置一次吗?每次调用编辑器时,DataGrid 是否都会创建一个新的字段控件?
于 2013-03-08T21:39:07.760 回答