Reputation: 1
I'm trying to have the textbox display a message when an item is selected on the combobox. However, nothing is happening. I tried SelectedItem and SelectedText and I get nothing in my text box, I even tried to hide one of the labels, again...nothing.
Here is the Code:
// 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();
}
}
Upvotes: 0
Views: 1991
Reputation: 1066
Try SelectedItem->Text. That's how you get the selected text for a ComboBox.
UPDATE: I googled a bit for you, and found this -- hope it helps!
http://www.programmersheaven.com/discussion/254711/getting-the-value-of-a-combobox
Upvotes: 2