首页 > 解决方案 > 如何从复选框 DLGIdentifier 启用条目?

问题描述

在上一个问题的答案中,我展示了如何在更改复选框状态时启用条目。这一次,我想创建多个由相应复选框控制的条目。

对于每个复选框,我使用 DLGIdentifier 对其进行标记,然后使用 DLGEnabled(self.LookupElement("entryId"), self.LookupElement("cb_ID").DLGGetValue()) 启用/禁用它,但它失败了 QQ 有谁知道如何解决它?先感谢您。

这是我的代码。

class TestUI : UIFrame{
    number true, false, n_items
    
    TestUI(object self){
        true=1; false=0;
        result("TestUI ["+self.ScriptObjectGetID()+"] constructed\n")
    };
    
    ~TestUI(object self){
        result("TestUI ["+self.ScriptObjectGetID()+"] destructed\n")
    };
    
    void SelectAction(object self, TagGroup tgItem){
        for(number i=0;i<n_items;i++){
            // change state, but it failed.
            DLGEnabled(self.LookupElement("num2_"+(i+1)),self.LookupElement("cb_"+(i+1)).DLGGetValue())
            // the values of each checkbox are retured correctly.
            result(i+":"+self.LookupElement("cb_"+(i+1)).DLGGetValue()+"\n")
        };
    };
    
    TagGroup InputGenerator(object self, number i){
        // Entry template
        TagGroup tgBox = DLGCreateBox("Box_"+(i+1))
        
        TagGroup tgLable = DLGCreateLabel("#")
        // each elements are using DLGIdentifier to label it
        TagGroup tgNumber1 = DLGCreateRealField(10,5,0).DLGIdentifier("num1_"+(i+1))
        TagGroup tgNumber2 = DLGCreateRealField(10,10,0).DLGIdentifier("num2_"+(i+1))
        TagGroup tgGroup = DLGGroupItems(tgLable,tgNumber1,tgNumber2).DLGTableLayout(3,1,0)
        tgBox.DLGAddElement(tgGroup)
        
        TagGroup cb = DLGCreateCheckBox("IsCheck", false,"SelectAction").DLGIdentifier("cb_"+(i+1))
        tgBox.DLGAddElement(cb)
        DLGEnabled(tgNumber2,cb.DLGGetValue())
        
        return tgBox
    }
    
    void CreateDialog(object self){
        TagGroup main = DLGCreateDialog("Test")
        n_items = 3
        for (number j=0; j<n_items; j++){
            //create multiple entries by for loop
            TagGroup item=self.InputGenerator(j)
            main.DLGAddElement(item)
        };
        self.init(main).Display("TestUI")
    };
};

{
    alloc(TestUI).CreateDialog()
};

标签: checkboxdialogdm-script

解决方案


您可能希望将SelectAction方法替换为以下内容:

void SelectAction(object self, TagGroup tgItem){
        // tgItem is the taggroup of the element that fired the action
        // so no for-loop for checking all is needed here.
        // tgItem.TagGroupOpenBrowserWindow("",0)
        number checked = tgItem.DLGGetValue()
        string IDcheck
        if (!tgItem.DLGGetIdentifier(IDcheck)) return
        string IDField = "num2_" + right( IDcheck, len(IDcheck)-3 )
    
        // The DLGEnable() command only changes the taggroup of the dialog 
        // but doesn't do anything with the dialog window itself.
        // There is a separate command to enable/disable an element of the dialog.
        // void SetElementIsEnabled( ScriptObject dialogUI, String item_identifier, Boolean is_enabled )

        self.SetElementIsEnabled(IDField ,checked)
        return      
    };

本质上,您需要不同的命令来更改显示的对话框。它已记录在案,但有点难以找到:

F1 帮助


推荐阅读