Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate a lot of label controls with data from an array
Message
From
07/03/2008 15:50:37
 
 
To
06/03/2008 12:15:24
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01299345
Message ID:
01299869
Views:
10
This message has been marked as the solution to the initial question of the thread.
Bilal,

No, you can't really do that, but what you could do is iterate through the Form's Controls collection, test which ones are TextBoxes, then assign the text to that control. In C# it would be something like this:
int ArrayIndex = 0;
for (int i=0; i < this.Controls.Count; i++)
{
    if (this.Controls[i] is TextBox)
    {
        ((TextBox)this.Controls[i]).Text = TheArray[ArrayIndex].ToString();
        ArrayIndex++;
    }
}
You can do the conversion to VB here: http://www.carlosag.net/Tools/CodeTranslator/

~~Bonnie


>I am a beginner using Visual Basic.Net and I find myself needing to populate a lot of label controls with data from an array. Is it possible to refere to the label names with a variable? For example - if I have labels named label1 and label2, can I assign their text value at runtime with some kind of variable to indicate the number portion of the name. Something like labeli.text = "something", then increment i by 1 and then repeat the statement - only this time labeli now becomes label2. This way I can assign all the text values of each label with a loop instead of coding them all out individually.
>
>Thanks for the help.
>
>Bilal.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform