Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

Can't Seem To Dynamically Generate Labels

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steven C - 31 Aug 2006 15:17 GMT
Hello:

I'm trying to dynamically generate some labels for a form, and I can't
seem to get it to work.  The code is as follows.  The first label is
generated, but subsequent labels are not.  Is there a better technique
for this

for(int i=0; i <= intLabCount; i++)
{
    strArrLabAccounts[i] = "lblCaption" + Convert.ToString(i).Trim();
    Label lblNewLabel = new Label();
    lblNewLabel.Parent = this.pgLiveView;
    lblNewLabel.Text = "Yahoo" + Convert.ToString(i);
    lblNewLabel.Location = new System.Drawing.Point(i*50,20);
    lblNewLabel.Visible = true;
    lblNewLabel.Name = strArrLabAccounts[i].ToString();
}
Cor Ligthert [MVP] - 31 Aug 2006 15:26 GMT
Steven,

I think you overdo it, but at least I miss something as

Controls.Add(lblNewLabel);

Cor

> Hello:
>
[quoted text clipped - 13 lines]
>     lblNewLabel.Name = strArrLabAccounts[i].ToString();
> }
Stoitcho Goutsev (100) - 31 Aug 2006 22:19 GMT
Steven,

I don't see anywhere in to code to add the labels to the form (or some other
control).

Could it be the the problem or you kust missed that line of code in the
snippet that you posted.
I find it strangle that you say the first label is only created.

Signature

HTH
Stoitcho Goutsev (100)

> Hello:
>
[quoted text clipped - 13 lines]
>     lblNewLabel.Name = strArrLabAccounts[i].ToString();
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.