DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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!

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links