control Array in dot net

H

haitham.karim

I am making a program to show information about the elements of the
periodic table. So I have a form with 104 buttons. How can I create
the same handler like clicking on the button then use the button index
to fetch the element information from the database without writing the
code 104 times!! I could do this easily with VB6 bot not with dot net.
Any help is appreciated.
 
A

Armin Zingler

I am making a program to show information about the elements of the
periodic table. So I have a form with 104 buttons. How can I create
the same handler like clicking on the button then use the button
index to fetch the element information from the database without
writing the code 104 times!! I could do this easily with VB6 bot not
with dot net. Any help is appreciated.

Please search the group first before asking. Asked yesterday:

http://groups.google.com/group/micr...8e2967b5d1a/e2c3b0866243bf3b#e2c3b0866243bf3b


Armin
 
P

Phill W.

I have a form with 104 buttons. How can I create
the same handler like clicking on the button then use the button index
to fetch the element information from the database without writing the
code 104 times!! I could do this easily with VB6 bot not with dot net.

Visual Basic no longer has VB 'Proper's Control Arrays but, to be fair,
it doesn't need them.

Sub AnyButton_Click( sender as Object, e as EventArgs ) _
Handles Button1.Click, Button2.Click, Button3.Click, ...

MsgBox( DirectCast( sender, Button ).Name & " was clicked" )

End Sub

Or, alternatively, use the AddHandler statement in code.

Of course, although we no longer have Control Arrays, we /can/ have
Arrays of Controls:

Dim oButtons as Button() = New Button() _
{ Button1, Button2, Button3 }

For Each eBtn as Button in oButtons
AddHandler eBtn.Click, AddressOf AnyButton_Click
Next

HTH,
Phill W.
 

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