473,385 Members | 1,693 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,385 software developers and data experts.

An array of controls

In versions of VB prior to .net, I was able to create in code an array of
controls, such as

for i = 1 to 10
Load Me.lblTest(i)
Me.lblTest(i).top = me.lblTest(i-1).top - me.lblTest(i-1).height - 200
Me.lblTest(i).visible = true
next i

where lblTest(0) already exists on the form.

How do I do this in VB.net

Thanks
Nov 21 '05 #1
3 1035
"Sheldon" <Sh*****@discussions.microsoft.com> schrieb:
In versions of VB prior to .net, I was able to create in code an array of
controls


Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

"Sheldon" <Sh*****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
In versions of VB prior to .net, I was able to create in code an array of
controls, such as

for i = 1 to 10
Load Me.lblTest(i)
Me.lblTest(i).top = me.lblTest(i-1).top - me.lblTest(i-1).height -
200
Me.lblTest(i).visible = true
next i

where lblTest(0) already exists on the form.

How do I do this in VB.net

Thanks


Read up on the .NET Framework Form.ControlCollection class in the help. You
also may find another article helpful: search in the help for "Controls
Collection Changes in Visual Basic .NET".

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 21 '05 #3
"Sheldon" <Sh*****@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
In versions of VB prior to .net, I was able to create in code an array of
controls, such as

for i = 1 to 10
Load Me.lblTest(i)
Me.lblTest(i).top = me.lblTest(i-1).top - me.lblTest(i-1).height -
200
Me.lblTest(i).visible = true
next i

where lblTest(0) already exists on the form.

How do I do this in VB.net

Thanks


You need to get used to the object thing in .net.
It's a different way of looking at things.
So..

You can inherit one control from another.
So you could create a new control based on like a "master" label0.
That way it inherits all the event code you have.

Depends on the reason you want to do this though.

Say you want to run access reports from vb.
So you have some code works out what you got in a given mdb dynamically and
your use of control array functionality was so you had a label and button
per report.
You want a list of reports, descriptions and buttons and all built
dynamically.
Click on a button and your code runs the report it's next to.
You could do this using a datagrid based on an array.
Arrays contain objects now.
So you can have a class exposes 3 properties, rep_description, rep_name,
rep_access_name.
Link a datagrid to an array of these.
You need to look into getting a button into a grid and turn off append but
that's all on george shepherd's faq page ( google, it now if you ain't read
his stuff).
Otherwise the code's kind of easier.
Well, less messy.
No mucking about getting button two under button3.
You can't hit the end of a page.
Well, maybe not the first time you write it, seeing as how it's different.
But the second time'll be easy.

If you were doing asp.net I reckon probably even simpler because you'd have
a more suitable control available.
Seems to me they invested more effort in the asp functionality.
Mind you, it needed fixing more.

--
Regards,
Andy O'Neill
Nov 21 '05 #4

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

Similar topics

3
by: Mani | last post by:
Hi, can anyone help me on how to create a control array in C++ builder like we create in VB. I have another question regarding controls. I want to clear a group of text boxes in the form on a...
10
by: James McGivney | last post by:
I have a project in ASP.NET using C#. I have a large number of Button Controls and a large number of ImageButton Controls. It would be convienent if I could refer to a specific control by it's...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
2
by: Yogi21 | last post by:
Hi I have a sorted array containing strings. I am iterating through the array and clearing the contents one by one using "array.BinarySearch" to find each element. So far so good. But the moment I...
20
by: samean | last post by:
Hello, Could you explain me,In VB6 using control array,and how about VB.net. Thanks
1
by: Jim McGivney | last post by:
I am working on an ASP.net project with code behind in C#. I must manipulate the contents of many label controls. In visual basic (VB6) I could place all the controls into a control array and...
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
5
by: WesIdell | last post by:
Hi All: I need some advice regarding a problem that I'm experiencing. I'm using a group of TextBox controls in the .aspx page and am using a function in the .cs code to perform some actions with...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.