for each
-
Heyas all, So let's say that my windows form has approx 20 different textbox controls on it. I'm wanted to do something like this:
for each(System::Windows::Forms::Textbox txt in MainForm) { if (txt.Text.Length > 0) DoSomething(); else if (txt.Text.Length == 0) DoSomethingElse(); } Obviously this is semipseudocode and doesn't work, would anyone be willing to show me this code in working order? I'd really appreciate it. Thanks, John
-
Heyas all, So let's say that my windows form has approx 20 different textbox controls on it. I'm wanted to do something like this:
for each(System::Windows::Forms::Textbox txt in MainForm) { if (txt.Text.Length > 0) DoSomething(); else if (txt.Text.Length == 0) DoSomethingElse(); } Obviously this is semipseudocode and doesn't work, would anyone be willing to show me this code in working order? I'd really appreciate it. Thanks, John
MainForm is not a control! So your code won't work! for each (System::Windows::Forms::Control ^control in this->Controls) { if (control->GetType() == TextBox::typeid) { TextBox ^tb = safe_cast(control); tb->Text = tb->Name; } } -- modified at 17:55 Friday 17th March, 2006
-
MainForm is not a control! So your code won't work! for each (System::Windows::Forms::Control ^control in this->Controls) { if (control->GetType() == TextBox::typeid) { TextBox ^tb = safe_cast(control); tb->Text = tb->Name; } } -- modified at 17:55 Friday 17th March, 2006
Hey George, I'm still working on this same problem, let me show you what I have:
for each(Control^ ctrl in this->AddCustomerFormSiteInformationGroupBox->Controls) { if (ctrl->GetType() == TextBox) { TextBox^ txt = safe_cast<TextBox^>(ctrl); if (txt->Text->Length > 0) { if (MessageBox::Show("Discard Changes?", "Confirm", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == ::DialogResult::Yes) this->Close(); } else { this->Close(); } } }
I'm not sure what you're refering to with TextBox::typeid Thanks, John -
Hey George, I'm still working on this same problem, let me show you what I have:
for each(Control^ ctrl in this->AddCustomerFormSiteInformationGroupBox->Controls) { if (ctrl->GetType() == TextBox) { TextBox^ txt = safe_cast<TextBox^>(ctrl); if (txt->Text->Length > 0) { if (MessageBox::Show("Discard Changes?", "Confirm", MessageBoxButtons::YesNo, MessageBoxIcon::Warning) == ::DialogResult::Yes) this->Close(); } else { this->Close(); } } }
I'm not sure what you're refering to with TextBox::typeid Thanks, Johnfor each (System::Windows::Forms::Control ^control in this->Controls) { if (control->GetType() == TextBox::typeid) { TextBox ^tb = safe_cast(control); tb->Text = tb->Name; } } TextBox::typeid is the same as __typeof(TextBox) in MC++ 7.1 I hope that helps!