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. C#
  4. Changing value of all TextBoxes

Changing value of all TextBoxes

Scheduled Pinned Locked Moved C#
csharpvisual-studiohelpquestion
5 Posts 3 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.
  • G Offline
    G Offline
    Gavin_Mannion
    wrote on last edited by
    #1

    Hi All, Simple question here (I Hope) I need to reset all my textboxes back to blank and am trying to do it in a nice clean loop. I have the following but it does not work

    foreach (TextBox t in this)
    {
    t.Text = "";
    }

    I am getting the error message

    C:\Documents and Settings\gavin\My Documents\Visual Studio Projects\LTBRMaintenance\EditClinic.cs(487): foreach statement cannot operate on variables of type 'LTBRMaintenance.EditClinic' because 'LTBRMaintenance.EditClinic' does not contain a definition for 'GetEnumerator', or it is inaccessible

    I have a feeling I am nearly there but am missing something obvious.. Thanks

    S 1 Reply Last reply
    0
    • G Gavin_Mannion

      Hi All, Simple question here (I Hope) I need to reset all my textboxes back to blank and am trying to do it in a nice clean loop. I have the following but it does not work

      foreach (TextBox t in this)
      {
      t.Text = "";
      }

      I am getting the error message

      C:\Documents and Settings\gavin\My Documents\Visual Studio Projects\LTBRMaintenance\EditClinic.cs(487): foreach statement cannot operate on variables of type 'LTBRMaintenance.EditClinic' because 'LTBRMaintenance.EditClinic' does not contain a definition for 'GetEnumerator', or it is inaccessible

      I have a feeling I am nearly there but am missing something obvious.. Thanks

      S Offline
      S Offline
      SimonS
      wrote on last edited by
      #2

      I think that this is just an object and doesn't natively expose a GetEnumerator method. Try this: foreach(Control c in this.Controls) { if(c.GetType().ToString()=="System.Windows.Forms.TextBox") c.Text="new vlaue"; } Cheers, Simon X-5 452 rules.

      G J 2 Replies Last reply
      0
      • S SimonS

        I think that this is just an object and doesn't natively expose a GetEnumerator method. Try this: foreach(Control c in this.Controls) { if(c.GetType().ToString()=="System.Windows.Forms.TextBox") c.Text="new vlaue"; } Cheers, Simon X-5 452 rules.

        G Offline
        G Offline
        Gavin_Mannion
        wrote on last edited by
        #3

        That is exactly it. :) Thanks :)

        1 Reply Last reply
        0
        • S SimonS

          I think that this is just an object and doesn't natively expose a GetEnumerator method. Try this: foreach(Control c in this.Controls) { if(c.GetType().ToString()=="System.Windows.Forms.TextBox") c.Text="new vlaue"; } Cheers, Simon X-5 452 rules.

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          simons wrote: if(c.GetType().ToString()=="System.Windows.Forms.TextBox") You could also use; if( c is System.Windows.Forms.TextBox ) this lets the value change for controls derived from TextBox too :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

          S 1 Reply Last reply
          0
          • J James T Johnson

            simons wrote: if(c.GetType().ToString()=="System.Windows.Forms.TextBox") You could also use; if( c is System.Windows.Forms.TextBox ) this lets the value change for controls derived from TextBox too :) James Sonork ID: 100.11138 - Hasaki "My words but a whisper -- your deafness a SHOUT. I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972

            S Offline
            S Offline
            SimonS
            wrote on last edited by
            #5

            James T. Johnson wrote: if( c is System.Windows.Forms.TextBox ) That's a better way. Probably more robust too (if MS changes the text of class names). Cheers, Simon X-5 452 rules.

            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