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. How can I use the loop indexing for a textbox's name?

How can I use the loop indexing for a textbox's name?

Scheduled Pinned Locked Moved C#
questiondatabasehelp
4 Posts 4 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.
  • K Offline
    K Offline
    Khoramdin
    wrote on last edited by
    #1

    Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean: for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); } Thank you very much and have a great day. Khoramdin

    F G C 3 Replies Last reply
    0
    • K Khoramdin

      Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean: for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); } Thank you very much and have a great day. Khoramdin

      F Offline
      F Offline
      fang_eric
      wrote on last edited by
      #2

      do it in other ways. TextBox tb[] = {textbox1,textbox2,...,textbox5}; for(i=0;i<5;i++) { tb[i].Text = foundRows[i].ToString(); }

      1 Reply Last reply
      0
      • K Khoramdin

        Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean: for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); } Thank you very much and have a great day. Khoramdin

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        Lets say these 5 buttons are placed on Form1. Than you can write this: for(int i=1,i<6 i++) { Form1.Controls["textbox"+i.ToString()].Text=something; }

        1 Reply Last reply
        0
        • K Khoramdin

          Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean: for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); } Thank you very much and have a great day. Khoramdin

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Khoramdin wrote:

          textBox1 textBox2 textBox3 textBox4 textBox5

          If you give them real names, they may make more sense. Then add a tag to each which is the same as the column you want to assign there, assuming they are columns from a single record. Then loop through the controls collection looking for the one with that tag. Or you can create an array of textboxes.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          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