Solved

How to create textbox and label controls dynamically?

Posted on 2007-03-19
1
211 Views
Last Modified: 2010-04-23
I am trying to find a way to create label and textbox controls dynamically when a user hits a button through code.

LabelValue1: [TextBox1]
LabelValue2: [TextBox2]

The following code is giving me an error after the Dim statement.

Error: Variable ‘NewLabel; is used before it has been assigned a value.  A null reference exception could result at runtime.

            Dim NewLabel As Label
            NewLabel.Height = 19
            NewLabel.Width = 25
            NewLabel.Text = "Nothing"
            NewLabel.Location = New System.Drawing.Point(13, 13)

            Me.Controls.Add(NewLabel)

What am I missing?
0
Comment
Question by:endrec
1 Comment
 
LVL 6

Accepted Solution

by:
kerryw60 earned 500 total points
ID: 18751331
Dim NewLabel As New Label
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question