Adding Values to Text Feilds through incrmental moves

Gerald

Member
Joined
Dec 18, 2012
Messages
6
Programming Experience
Beginner
The best way I can describe my issue is this:
1) I am trying to add values into text boxes.
a. Names are value1, value2?.value24.
2) I trying to usefor(nextBox=24;nextBox<25;nextBox++)
3) I am trying to take a derived value located inderivedArray[nextBox] from another location and add it to value(nextbox).
4) My problem is I am not sure how I can incrementthe next textbox in the chain and then add the derived value in its place.
5) I am not storing this information in the textboxes just trying to use them to organize and display the information for theuser.
Any help would be appreciated.

This is being handled in VS2012 and I am using Windows Formsfor this project.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,273
Location
Sydney, Australia
Programming Experience
10+
It sounds like you're trying to access a number of sequentially named TextBoxes on a form. You can index the form's Controls collection by name to get a control, so you can do something like this:
for (int i = 1; i <= 24; i++)
{
    var field = Controls["value" + i];

    // Use field here;
}
The 'field' variable is type Control, which is fine if all you want to access is the Text property. If you want a member of the specific type of control then you'll need to cast.
 
Top Bottom