Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. for each

for each

Scheduled Pinned Locked Moved Managed C++/CLI
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    John L DeVito
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • J John L DeVito

      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

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • G George L Jackson

        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

        J Offline
        J Offline
        John L DeVito
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • J John L DeVito

          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

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          for 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!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups