Flex Combobox 奇怪的問題 (Flex Combobox strange problem)


問題描述

Flex Combobox 奇怪的問題 (Flex Combobox strange problem)

I am facing a strange problem with the combobox in Flex. In the following code : 

    public function rollCombo(cmb:ComboBox,value:String):void
    {
            if(value=='') return;
            var i:int=0;
            cmb.selectedIndex = 0;
            var dp1:XMLListCollection =   (XMLListCollection(cmb.dataProvider);
            trace(value);
            while(dp1[i]!=value && i<dp1.length)
              cmb.selectedIndex = ++i;
              cmb.validateNow();
              cmb.validateDisplayList();

            trace(cmb.selectedLabel);
    }

in an example case, at the end of the execution of the function, i is 7, and cmb.selectedLabel is "xyz"(according to the trace output), but the label displayed in the combobox is a different one.

Also, this is rather unpredictable. It happens sometimes and not always.


參考解法

方法 1:

The last selectedIndex is out of range, because you use pre-incrementation. Which means i becomes dp1.length before the test, and it's assigned to selectedIndex too. That might explain the weird behavior. You'll probably want to use post-incrementation.

Also. The only thing that gets executed in that while looks to be 

cmb.selectedIndex = ++i;

I don't know if that's what you wanted, but you might need some "{}" there.

(by simplfuzzbug-a-lot)

參考文件

  1. Flex Combobox strange problem (CC BY-SA 3.0/4.0)

#Combobox #actionscript-3 #apache-flex






相關問題

tcl/tk 小部件組合框失去焦點 (tcl/tk widget combobox loses focus)

Flex Combobox 奇怪的問題 (Flex Combobox strange problem)

在組合框中對齊文本 (Align Text in Combobox)

如何同時綁定到 ComboBox 中的兩個不同的依賴屬性? (How do I bind to two different dependency properties in a ComboBox at the same time?)

在綁定到字典的組合框中設置所選項目 (Setting selected item in combobox bound to dictionary)

easyUI datagrid內部編輯組合框無法選擇默認值 (easyUI datagrid inner edit combobox cannot selected default value)

VBA:數據輸入組合框有效,但命令按鈕給出“無效的屬性值”錯誤 (VBA: Data entry into combobox works, but command button gives "Invalid property value" error)

vb.net - 組合框總是選擇第一個值 (vb.net - combo box always select the first value)

打開 ComboBox DropDown 時不要選擇文本輸入 (Do not select text input when ComboBox DropDown is opened)

如何使用相同的數據源設置多個組合框? (How can I set up multiple combo-boxes with the same data source?)

如何使用 QtreeView 在 QComboBox 中設置所選項目 (How to set selected item in QComboBox with QtreeView)

Tkinter 組合框 Python (Tkinter Combobox Python)







留言討論