Hello,
I have a quick question about C#. I used to do a lot of PHP
programming, and there was a function that I found to be very useful.
It was the eval() function, and it took a string, and evaluated it as
PHP code. Now, is there a function in C# that allows me to do this as
well The reason I want to do this is, I have 81 textboxes setup in a
grid. I want to be able to make changes to all the textboxes at once,
and also update the value of a specific textbox in the grid. Now I got
around this by creating an array of textboxes, but the design mode of
C# does not work when I do this, although the program executes
perfectly, but I would like the functionality of using the design mode.
So, my idea was to have the textboxes named "grid_1, grid_2" ect. If
there was an eval() function, I could simply do this:
eval("grid_" + i + ".Text = myText;");
Is there a function that can accomplish this, or even a better way to accomplish creating an array of textboxes

Execute String?
Jamie Eckman
You can play around with reflection to get the controls by name too, but it's slow; so the option I can recommend you is through the Controls collection of the parent control of your TextBoxes. I understand that you want to name your TextBoxes in grid_1, grid_2 etc...but in Controls collection, you access them via index or use the foreach to loop through the collection, this allows you to update the control when you found the name of the textbox:
public void SetText( string controlname, string text )
{
foreach( Control ctl in MyGrid.Controls )
{
if ( ctl is TextBox && ctl.Name == controlname ) // Search the control
{
ctl.Text = text; // Set the text here...
break;
}
}
}
The above code will allow you to search for the TextBox in a Parent control named MyGrid (assuming all your TextBoxes' parent is MyGrid). You can use it this way:
for (int i = 1; i <= textboxesCount; i++)
{
SetText( "grid_" + i.ToString(), "myText" );
}
Though its not that similar to the eval() function, I hope the code above helps.
Regards,
-chris