【问题标题】:How do I create an expanding field editor in a LiveCode DataGrid?如何在 LiveCode DataGrid 中创建扩展字段编辑器?
【发布时间】:2013-03-07 03:40:38
【问题描述】:

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

【问题讨论】:

    标签: datagrid livecode


    【解决方案1】:

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

    将字段编辑器行为按钮从 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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我认为它确实会即时创建该字段。无论哪种方式,与动态设置属性相比,编辑数据网格组中一个对象的属性都是一种更复杂的解决方案。 preOpenFieldEditor 处理程序是设置字段编辑器属性的文档化方法。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多