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. Controls

Controls

Scheduled Pinned Locked Moved C#
tutorialquestion
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.
  • P Offline
    P Offline
    papa80
    wrote on last edited by
    #1

    Hi How i can get control by names: For example i have 3 textbox with name tb0,tb1,tb2 i need to fill them in loop how to do that?? for(int i=0;i<3;i++) { TextBox tb=??? } GOod bye best regards

    when i want to read something good just seat and type it

    N 1 Reply Last reply
    0
    • P papa80

      Hi How i can get control by names: For example i have 3 textbox with name tb0,tb1,tb2 i need to fill them in loop how to do that?? for(int i=0;i<3;i++) { TextBox tb=??? } GOod bye best regards

      when i want to read something good just seat and type it

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello To get a control by name use this.Controls["Controlname"], like this

      for(int i=0;i<3;i++)
      {
      TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
      }

      Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the is or as keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.

      TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];

      Regards:rose:

      P I 2 Replies Last reply
      0
      • N Nader Elshehabi

        Hello To get a control by name use this.Controls["Controlname"], like this

        for(int i=0;i<3;i++)
        {
        TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
        }

        Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the is or as keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.

        TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];

        Regards:rose:

        P Offline
        P Offline
        papa80
        wrote on last edited by
        #3

        Thank's a lot

        when i want to read something good just seat and type it

        1 Reply Last reply
        0
        • N Nader Elshehabi

          Hello To get a control by name use this.Controls["Controlname"], like this

          for(int i=0;i<3;i++)
          {
          TextBox tb= (TextBox)this.Controls["tb" + i.ToString()];
          }

          Yet such a loop doesn't have any error checking. You must make sure that the control is a TextBox using the is or as keywords. Also if your textbox is in a container -eg. GroupBox-, Then it's inside the controls of that GroupBox not the form, ie.

          TextBox tb= (TextBox)this.MyGroupBox.Controls["tb" + i.ToString()];

          Regards:rose:

          I Offline
          I Offline
          iqazi
          wrote on last edited by
          #4

          //if controls are on form foreach(Control c in this.Controls) { if(c is textbox) c.Text = "some text"; } //if controls are in some container foreach(Control c in this.ContainerName.Controls) { if(c is textbox) c.Text = "some text"; } i hope it works

          ihtesham

          N 1 Reply Last reply
          0
          • I iqazi

            //if controls are on form foreach(Control c in this.Controls) { if(c is textbox) c.Text = "some text"; } //if controls are in some container foreach(Control c in this.ContainerName.Controls) { if(c is textbox) c.Text = "some text"; } i hope it works

            ihtesham

            N Offline
            N Offline
            Nader Elshehabi
            wrote on last edited by
            #5

            Gee!! Thanks for your reply!:laugh: Only one problem is that it wasn't me who asked the question!!;P He won't get a notification of your reply if you replied to me. Repost your reply by replying to his original post.

            Regards:rose:

            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