L
lgbjr
Hi All,
I need to specify a control's name using a variable and I can't seem to get
it right.
I have several labels on a form and depending on a user's actions, a label's
text is changed. Rather than writing code for each label and each event that
can change the labels, I'm trying to do all of the changes in one event, but
I need to specify the label's name using a variable.
for instance, I have an integer (i) that is incremented in a loop. The label
that I want to change in each pass of the loop might be Label+i.ToString.
What I can't figure out is how to make a change to the label. This is what
I'm trying, but I get a Cast not Valid error:
DirectCast("Label"+i.ToString,System.Windows.Forms.Label).text="MyText"
TIA
Lee
I need to specify a control's name using a variable and I can't seem to get
it right.
I have several labels on a form and depending on a user's actions, a label's
text is changed. Rather than writing code for each label and each event that
can change the labels, I'm trying to do all of the changes in one event, but
I need to specify the label's name using a variable.
for instance, I have an integer (i) that is incremented in a loop. The label
that I want to change in each pass of the loop might be Label+i.ToString.
What I can't figure out is how to make a change to the label. This is what
I'm trying, but I get a Cast not Valid error:
DirectCast("Label"+i.ToString,System.Windows.Forms.Label).text="MyText"
TIA
Lee