What is the best way to handle a single event that might occur in multiple controls of the same type

S

Siv

Hi,
I am struggling with VB.NET's lack of indexing on controls.

I have a form with 23 text boxes and I want to be able to drag some items in
a list to any one of those text boxes. In VB6 I would have made a control
array of text boxes and put my dragenter and dragdrop stuff in a single
event procedures that related to the array. Is there a neat way to do this
in .NET or do I have to create 23 separate event procedures? one for each
text box. It seems very wasteful of resources?

Siv
 
H

Hal Rosser

Siv said:
Hi,
I am struggling with VB.NET's lack of indexing on controls.

I have a form with 23 text boxes and I want to be able to drag some items in
a list to any one of those text boxes. In VB6 I would have made a control
array of text boxes and put my dragenter and dragdrop stuff in a single
event procedures that related to the array. Is there a neat way to do this
in .NET or do I have to create 23 separate event procedures? one for each
text box. It seems very wasteful of resources?

Siv

Look at the end of any event procedure declaration - you'll see the 'handles
clause'
just add to it
ie: "handles textbox1.change, textbox2.change, textbox3.change....etc"
 
C

Cor Ligthert

Siv,
Hi,
I am struggling with VB.NET's lack of indexing on controls.

How you come at that idea?

Only there are so much methods for that.

This is what I wrote the last 3 months about that in this newsgroup alone
http://tinyurl.com/create.php

And this is than only the array of controls, for handling it would be much
more. One of the methods is as Hal wrote.

I hope this helps?

Cor
 
H

Herfried K. Wagner [MVP]

Siv said:
I have a form with 23 text boxes and I want to be able to drag some items
in a list to any one of those text boxes. In VB6 I would have made a
control array of text boxes and put my dragenter and dragdrop stuff in a
single event procedures that related to the array. Is there a neat way to
do this in .NET or do I have to create 23 separate event procedures? one
for each text box. It seems very wasteful of resources?

\\\
Private Sub Button_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles Button1.Click, Button2.Click, Button3.Click
MsgBox(DirectCast(sender, Button).Name)
End Sub
///

Take a look at the 'AddHandler' and 'RemoveHandler' keywords too.
 
S

Siv

Hal,
I suppose it had to be this simple as I couldn't find this in any of the
VB.NET books I have (3 in all)
Thanks for your help.
I had almost worked this out myself, but wasn't convinced.

Siv
 
S

Siv

I didn't either,
I had got my answer from some of the prior posters and the link did look as
if it might be incorrect.

Cor has corrected it now.

Siv
 
S

Siv

Cor,
I was thanking you for responding, I didn't follow the link as I had
already got the answer from the first poster (Hal Rosser) and Herfried has
filled in the remaining issue about how you identify which control triggered
the event. I suspected that the link was in error and didn't follow it.

Again, thanks.
Siv
 

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