带有If语句的组合框和文本框

时间:2013-11-19 19:50:56

标签: visual-c++ combobox c++-cli

我正在尝试让文本框在组合框中选择项目时显示消息。然而,一切都没有发生。我尝试了SelectedItem和SelectedText,我的文本框中什么都没有,我甚至试图隐藏其中一个标签,再次......没有。

以下是代码:

        // comboBox1
        // 
        this->comboBox1->FormattingEnabled = true;
        this->comboBox1->Location = System::Drawing::Point(41, 39);
        this->comboBox1->Name = L"comboBox1";
        this->comboBox1->Size = System::Drawing::Size(121, 21);
        this->comboBox1->TabIndex = 7;
        this->comboBox1->Items->Add("300");
        this->comboBox1->Items->Add("1200");
        this->comboBox1->Items->Add("2400");
        this->comboBox1->Items->Add("9600");
        this->comboBox1->Items->Add("14400");
        this->comboBox1->Items->Add("19.2K");
        this->comboBox1->Items->Add("57.6K");
        this->comboBox1->Items->Add("115.2K");


private: System::Void comboBox1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
             if(comboBox1->SelectedItem->ToString() == "300") 
             {
                 textBox1->Text= "Hello World?";
                 label1->Hide();
             }
         }

1 个答案:

答案 0 :(得分:2)

尝试SelectedItem->文字。这就是你如何获得ComboBox的选定文本。

更新:我为你搜索了一下,发现了这个 - 希望它有所帮助!

http://www.programmersheaven.com/discussion/254711/getting-the-value-of-a-combobox