By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,261 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,261 IT Pros & Developers. It's quick & easy.

control Array in dot net

P: n/a
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.

Oct 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<ha***********@gmail.comschrieb
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/micro...c3b0866243bf3b
Armin

Oct 25 '07 #2

P: n/a
ha***********@gmail.com wrote:
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.
Oct 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.