473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

VB .NET dynamic number of controls...

Is it possible to dynamically add controls (speciifcally
System.Windows.Forms.ProgressBar and System.Windows.Forms.Label) to a panel
to a form and have them display (and fucntion) at run time?

I've been trying todo this by creating arrays of progressbars and labels.
Then for each item in the root nods of a treeView that I need to track
progress on, I create a bar and label and add them to a panel. The problem is
that when I display the panel, its blank... no labels, no progress bars.
Here's a code snippet:

'pnlProgress declared above...
'x declared above...
Dim pgb(x) As System.Windows.Forms.ProgressBar
Dim lbl(x) As System.Windows.Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.Nodes
'Set up progress bars
pgb(i) = New System.Windows.Forms.ProgressBar
pgb(i).Dock = DockStyle.Fill
pgb(i).Minimum = 0
pgb(i).Maximum = 100
pgb(i).Value = 50 just to test the bar
pgb(i).Visible = True

'Set up labels
lbl(i) = New System.Windows.Forms.Label
lbl(i).Text = tn.getSlideName() & " content progress"
lbl(i).Dock = DockStyle.Left
lbl(i).Visible = True

Me.pnlProgress.Controls.Add(pgb(i))
Me.pnlProgress.Controls.Add(lbl(i))

i += 1
Next

Do I have to declare all the objects as "Friend WithEvents " at the top of
the form before I begin (no longer dynamic...)

I pretty stuck on this... Is there something I'm missing? (hopefully
something simple)

Any help would be appreciated...

Charles
Aug 24 '05 #1
5 8803
Hi Charles,

How's Camilla? (sorry... I couldn't help myself... :-)

OK, jokes apart, it's very easy to add controls at runtime anywhere in
dotnet. Even hooking up events to any sub or function (wich was a
nightmare in VB6).

All you have to do is simply follow the lead of the designer... Check
the code the designer generates when you add a control.

Regards,

Paulo

Aug 24 '05 #2
Forget WithEvents.

Use AddHandler obj.Event, AddressOf MethodName

"hz****@nopost.com" <hz*************@discussions.microsoft.com> wrote in
message news:EF**********************************@microsof t.com...
Is it possible to dynamically add controls (speciifcally
System.Windows.Forms.ProgressBar and System.Windows.Forms.Label) to a
panel
to a form and have them display (and fucntion) at run time?

I've been trying todo this by creating arrays of progressbars and labels.
Then for each item in the root nods of a treeView that I need to track
progress on, I create a bar and label and add them to a panel. The problem
is
that when I display the panel, its blank... no labels, no progress bars.
Here's a code snippet:

'pnlProgress declared above...
'x declared above...
Dim pgb(x) As System.Windows.Forms.ProgressBar
Dim lbl(x) As System.Windows.Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.Nodes
'Set up progress bars
pgb(i) = New System.Windows.Forms.ProgressBar
pgb(i).Dock = DockStyle.Fill
pgb(i).Minimum = 0
pgb(i).Maximum = 100
pgb(i).Value = 50 just to test the bar
pgb(i).Visible = True

'Set up labels
lbl(i) = New System.Windows.Forms.Label
lbl(i).Text = tn.getSlideName() & " content progress"
lbl(i).Dock = DockStyle.Left
lbl(i).Visible = True

Me.pnlProgress.Controls.Add(pgb(i))
Me.pnlProgress.Controls.Add(lbl(i))

i += 1
Next

Do I have to declare all the objects as "Friend WithEvents " at the top of
the form before I begin (no longer dynamic...)

I pretty stuck on this... Is there something I'm missing? (hopefully
something simple)

Any help would be appreciated...

Charles

Aug 25 '05 #3
Hi,

See this sample on our website

http://www.windowsformsdatagridhelp....2-03abce36aa60

I hope this helps,

Cor
Aug 25 '05 #4
Ok, so now that I know its possible - other than the erronous Dock values
below (just assume they are all docked to the top) - why isn't the code below
working for me? I modeled it after what the form designer created!
"hz****@nopost.com" wrote:
Is it possible to dynamically add controls (speciifcally
System.Windows.Forms.ProgressBar and System.Windows.Forms.Label) to a panel
to a form and have them display (and fucntion) at run time?

I've been trying todo this by creating arrays of progressbars and labels.
Then for each item in the root nods of a treeView that I need to track
progress on, I create a bar and label and add them to a panel. The problem is
that when I display the panel, its blank... no labels, no progress bars.
Here's a code snippet:

'pnlProgress declared above...
'x declared above...
Dim pgb(x) As System.Windows.Forms.ProgressBar
Dim lbl(x) As System.Windows.Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.Nodes
'Set up progress bars
pgb(i) = New System.Windows.Forms.ProgressBar
pgb(i).Dock = DockStyle.Fill
pgb(i).Minimum = 0
pgb(i).Maximum = 100
pgb(i).Value = 50 just to test the bar
pgb(i).Visible = True

'Set up labels
lbl(i) = New System.Windows.Forms.Label
lbl(i).Text = tn.getSlideName() & " content progress"
lbl(i).Dock = DockStyle.Left
lbl(i).Visible = True

Me.pnlProgress.Controls.Add(pgb(i))
Me.pnlProgress.Controls.Add(lbl(i))

i += 1
Next

Do I have to declare all the objects as "Friend WithEvents " at the top of
the form before I begin (no longer dynamic...)

I pretty stuck on this... Is there something I'm missing? (hopefully
something simple)

Any help would be appreciated...

Charles

Aug 25 '05 #5
Probably are they docked each over each other.

In your situation I would first test it with docking anything

Cor
Aug 25 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: CSDunn | last post by:
Hello, I have a situation with MS Access 2000 in which I need to display report data in spreadsheet orientation (much like a datasheet view for a form). If you think of the report in terms of what...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
1
by: Will | last post by:
Hi all. I'm learning VB.Net and am developing a WinForms app. I'm trying to make an app that I will use to scan in one or more than on image. I want to use a tabbed interface to hold each image....
6
by: dhnriverside | last post by:
Hi peeps, I'm trying to create some controls textboxes at runtime, based on the number of items in a IETreeView that are checked. That I can do, I've got a place holder and I can create the...
2
by: WolfyUK | last post by:
Hello, I have a standard asp:DataGrid called CasesGrid that I wish to write my own paging controls for. The aim is to get something like the following rendered to screen: << First < Previous...
3
by: HP | last post by:
Hi there The problem of dynamically created controls vs viewstate is widely known one. To access values of controls they have to be recreated on Page_Load. Unfortunately it causes many...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
4
Frinavale
by: Frinavale | last post by:
Introduction Sometimes, when developing web applications, we need to be able to dynamically load controls based on user selections. The following article describes a simple scenario where TextBox...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.