473,785 Members | 2,297 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB .NET dynamic number of controls...

Is it possible to dynamically add controls (speciifcally
System.Windows. Forms.ProgressB ar 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.ProgressB ar
Dim lbl(x) As System.Windows. Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.No des
'Set up progress bars
pgb(i) = New System.Windows. Forms.ProgressB ar
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(pg b(i))
Me.pnlProgress. Controls.Add(lb l(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 8830
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.m icrosoft.com> wrote in
message news:EF******** *************** ***********@mic rosoft.com...
Is it possible to dynamically add controls (speciifcally
System.Windows. Forms.ProgressB ar 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.ProgressB ar
Dim lbl(x) As System.Windows. Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.No des
'Set up progress bars
pgb(i) = New System.Windows. Forms.ProgressB ar
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(pg b(i))
Me.pnlProgress. Controls.Add(lb l(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.ProgressB ar 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.ProgressB ar
Dim lbl(x) As System.Windows. Forms.Label
Dim tn As myTreeNode
Dim i As Integer = 0

For Each tn In Me.treeView1.No des
'Set up progress bars
pgb(i) = New System.Windows. Forms.ProgressB ar
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(pg b(i))
Me.pnlProgress. Controls.Add(lb l(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
3717
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 a spreadsheet might show, the column names will actually be dynamic, based on data from a SQL Server 2000 database. The row data will also come from the same database. So in this case, I will have a main report and a subreport. I've already tried...
1
17673
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 Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
1
6323
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. Here's the code I'm using for testing purposes. I've got the code in the form's load event, but I think I'd have the same problems no matter where the code existed. Right now, the form has an empty tab control, everthing else is dynamic. <code>
6
2238
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 corrent number of controls. The problem is that they appear next to each other. I want to create the controls with some wording to the left of them (again, dynamically generated). Normally id use <table> with two colums, one for the
2
2714
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 1 2 3 4 5 ... Next Last >> I have achieved the first/previous/next/last buttons quite easily as follows in the ASPX (1.1) page:
3
2588
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 problems in the following (rather common, I guess) scenario: The controls are created dynamically. Their number and contents
0
5293
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 the days in the week with dates and textboxes to fill in some data. row 1: question
4
51672
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 controls need to be dynamically loaded according to user input. This simple example can be further extended to dynamically load custom web user controls. Background Please familiarize yourself with the ASP.NET Page Life Cycle. It is crucial to...
1
4660
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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3501
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- 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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.