A-Control Array ?

J

Jim Burns

I just started with vb.net and I don't understand why there are no control
arrays.
what replaced them.
I was trying to do drag and drop(What happened with that) and it looked like
with no control array I have to write code in for every control?
That cant be possible.
I looked at the help files and it looks like I can set an event handler but
there has to be a better way then typing Handles pic1.click,pic2.click
It would be a lot of typing for 60 controls
 
C

Cor Ligthert

Jim,

This newsgroups is full of your question.

The term "Control Array" as it was in VB6 is no more.

There are still arrays of controls, even more, every control has a control
array where in are the childs controls again.

However there is not any more a property for that in the Ide. The array
(collection) is standard in the parent control object (although you can
simulate tho get any control using an array by instance using an hashtable
or any other collection/array).

(Do not forget where VB6 has only the collection and the array, has dotNet
much more for that and much more dynamicly)

Form
panel1
textbox1
textbox2
panel2
textbox3
button1

Form has in its control array (collection) panel1 and panel2
Panel1 has in its control collection textbox1 and textbox2
Panel2.....

I hope this helps?

Cor
 
P

Paul Clement

¤ I just started with vb.net and I don't understand why there are no control
¤ arrays.
¤ what replaced them.
¤ I was trying to do drag and drop(What happened with that) and it looked like
¤ with no control array I have to write code in for every control?
¤ That cant be possible.
¤ I looked at the help files and it looks like I can set an event handler but
¤ there has to be a better way then typing Handles pic1.click,pic2.click
¤ It would be a lot of typing for 60 controls

That is pretty much the recommended method since controls have no built-in index property.

http://msdn.microsoft.com/library/d.../vbconcontrolarraychangesinvisualbasicnet.asp


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
H

Herfried K. Wagner [MVP]

Jim Burns said:
I just started with vb.net and I don't understand why there are no control
arrays.
what replaced them.

Accessing controls by their names or indices
I was trying to do drag and drop(What happened with that) and it looked
like
with no control array I have to write code in for every control?
That cant be possible.
I looked at the help files and it looks like I can set an event handler
but
there has to be a better way then typing Handles pic1.click,pic2.click
It would be a lot of typing for 60 controls

You can loop through the controls and use 'AddHandler' to add a handler to
the controls' events.
 
G

Guest

Cor, when you have a form with the two panels with children textboxes, when
you enumerate all the controls on the form, are just the Panel 1 and Panel 2
enumerated or are all the children of the Panel 1 and Panel 2 enumerated as
well?
 
C

Cor Ligthert

Dennis,

In the collection of the form (you use "me." for that) are only the controls
that are its child.

When you want to use only some controls you can make your own array with
controls, wherever the control is on the form.

dim MyToUseControls() as Controls = {button1, button2, textbox1, etc)

When you want to get every control in an form it can be more a problem.
However I made once a recursive routine that find all controls in a form,
without trying to find how deep it is.

I showed it yesterday in a "class" in this newsgroup (OP was Stefan it in
the thread that started 2 after (in time so probably above) yours and with
that could use it in one time for the complete application.

I hope this gives some ideas?

Cor
 
J

Jim Burns

Isn't it so much simpler to copy paste 20 Image controls on a form ,vb
Index's for you . You double click on any image and vb sets up a event
handler for you .
Why would they take such functionality out.
 
C

Cor Ligthert

Jim,

That part what can be simpler can be a long discussion, I have beside things
that where in VB6 and not in VBNet a lot of things that can in my opinion be
simpler without even looking at VB6. By instance in the next version is the
creating from an event in VB style disapeared and it becomes C# style. I
find that as well a pity although in C# you can give your procedures a name
yourself.

However I am not the designer, that is the same probably as with your
clients when you change on good grounds parts. Than the user is after using
it a while is very happy with it, however for the first time he uses it
don't understand why he cannot use that old ones.

Looking at the past is for me not always the best measurement tool for that.
Sometimes you have to make decisions which can be an improvement for the
feature.

There are much more special designing tools from VB6 deleted. However there
are brought back a lot with a much wider scoop. For me this makes the
difference for using end user tools as Ms-Access or a programming tool as
VBNet is. I see VB6 as a kind of hybrid.

However just my opinion.

Cor
 
J

Jim Burns

I just became aware of all the controversy in the vb community on the .net
isn't vb thing . However .net is vb7 no mater what people say.
there is a lot of cool stuff in .net but I like using control arrays and the
class builder tool.
I'm learning .net from videos and about 2 hours ago I just did the lesson on
Extender controls.
Tonight I will start building A control Array ex tool That when dropped on a
form It will give some controls the ability to become control arrays by
right clicking on the control and selecting control array.
Its not so much that I cling to the past more like why should I go with out
control Arrays Because MS left them out When I could simple put then back
in, or actually mimic them with a collection and a vb6 like user feel.
 
N

Noozer

Jim Burns said:
I just became aware of all the controversy in the vb community on the .net
isn't vb thing . However .net is vb7 no mater what people say.

No it's not...
 
J

Jim Burns

Noozer Its bad enough when I post a ? on vb news groups I get shit about it
not being Visual Basics, But this is a vb.net group and some of use are
having a discussion. No one needs to hear your crying shit hear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top