Using a for loop to scroll through text boxes...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Using a for loop to scroll through text boxes...

  1. #1
    Join Date
    Apr 2005
    Posts
    1

    Question Using a for loop to scroll through text boxes...

    I have a program due tomorrow and hit a wall. I have a bunch of Text boxes set up in columns and rows and they are labeled in order like.....

    R1C1 R1C2 R1C3
    R2C1 R2C2 R2C3
    R3C1 R3C2 R3C3


    Im trying to start in column one, and input stuff from an array into its text field.....

    So in theory something like

    for (int i = 0; i < #rows; i++)
    {
    for (int j = 0; j < #columns; j++)
    {
    R1C1.Text = Int32.Parse(array[i,j]);
    }
    }

    Thats it, its simple but the problem is that i need the R1C1 to change with i and j......

    Im trying to explain this the best i can something like R[i]C[j].....


    Any help would be gratefull Thanks!!!
    Mike.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Try creating an array of textboxes:
    Code:
    private TextBox[,] controlArray = new TextBox[3, 3];
    
    for (int i = 0; i < 3; i++)
    {
    	for (int j = 0; j < 3; j++)
    	{
    		controlArray[i, j] = new TextBox();
    	}
    }
    
    // 
    // R1C1
    // 
    controlArray[0, 0].Location = new System.Drawing.Point(7, 5);
    controlArray[0, 0].Name = "R1C1";
    controlArray[0, 0].TabIndex = 0;
    controlArray[0, 0].Text = "";
    
    // etc.
    Then your assignment loop can look like this:
    Code:
    for (int i = 0; i < 3; i++)
    {
    	for (int j = 0; j < 3; j++)
    	{
    		controlArray[i, j].Text = Int32.Parse(array[i, j]);
    	}
    }
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center