簡體   English   中英

我們如何根據在 C# winform 的另一個組合框中選擇的值啟用 combobox

[英]how can we enable combobox based on the value selected in another combo box in C# winform

我們如何根據在 C# winform 的另一個組合框中選擇的值啟用 combobox。

我有兩個組合框,如下所示。 需要根據在第一個組合框中選擇的值啟用第二個組合框。 請注意,combobox1 的第一個值是默認值,需要禁用 combobox 2,但如果選擇了任何其他值,則應啟用 combobox 2。

在此處輸入圖像描述

假設你有 2 個組合框, combobox1combobox2

首先將事件偵聽器添加到combobox1 從那里,您可以檢查您的選項是否已被選中


        comboBox1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                //
                // Get the source of the component, which is our combo
                // box.
                //
                JComboBox comboBox = (JComboBox) event.getSource();

                Object selected = comboBox.getSelectedItem();
                if(selected.toString().equals("item1"))
                    combobox2.Enabled = True;
                else if(selected.toString().equals("item2"))
                    combobox2.Enabled = False;


            }
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM