March 1st, 2011, 07:16 PM
[Q] Issue with (RichTextBox)this.Controls[...];
As part of a larger project, on one form I have several rich text box controls. I am trying to access them all in the following for loop.
for (int i = 0; i < 7; i++)
RichTextBox txtbx = (RichTextBox)this.Controls["txtbx" + ((lanterntypes)i).ToString()];
string lines = new string;
lines = "goodbye";
for (int i2 = 1; i2 <= 3; i2++)
lines[i2] = "hello";
txtbx.Lines = lines;
However, txtbx returns as null for every iteration.
lanterntypes is an enum, of which the first is ParCan, and I have a rich text box called txtbxParCan so I don't think there is a problem with the names in fact being different.
I've used this method before in this same project succesfully with labels, so any help as to what I'm doing wrong now would be gratefully received.
Cheers to anyone who can help!
Tags for this Thread
Click Here to Expand Forum to Full Width