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

Dynamically handling events

P: n/a
I'm trying to implement the following code.
I want the base class to compile a collection of ComboBox controls and
handle their SelectedIndexChanged() event. I can't figure out how though.

I get a compile error on line 10.

"'cbx' is not an event of 'BaseClass'"

The first paramenter of the AddHandler statement is supposed to an Event,
but I don't know how to get a reference to the SelectedIndexChanged event of
cbx.
Public Class BaseClass
Dim colLookups As Collection

Protected Sub AddLookup(ByRef cbx As System.Windows.Forms.ComboBox)
10 AddHandler cbx, AddressOf cbxLookup_SelectedIndexChanged
colLookups.Add(cbx)
End Sub

Protected Overridable Sub cbxLookup_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)

End Sub
End Class

Public Class ChildClass
Inherits BaseClass

Public Sub CreateLookupControls()
'Creates any number of ComboBoxes (or none), changes various
settings, and sends each combo to MyBase.AddLookup()
End Sub
End Class
Any ideas??

Thanks!
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hello,

"Jeff Molby" <JeffMolby@C_mc_st.n_t> schrieb:
I want the base class to compile a collection of ComboBox
controls and handle their SelectedIndexChanged() event. I can't
figure out how though.

I get a compile error on line 10.

"'cbx' is not an event of 'BaseClass'" [...] AddHandler cbx, AddressOf cbxLookup_SelectedIndexChanged
\\\
AddHandler _
cbx.SelectedIndexChanged, _
AddressOf cbxLookup_SelectedIndexChanged
///
colLookups.Add(cbx)


--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
Herfried, you embarrass me.... How did I not figure that out?? Thanks for
your help!
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:eQ**************@TK2MSFTNGP12.phx.gbl...
Hello,

"Jeff Molby" <JeffMolby@C_mc_st.n_t> schrieb:
I want the base class to compile a collection of ComboBox
controls and handle their SelectedIndexChanged() event. I can't
figure out how though.

I get a compile error on line 10.

"'cbx' is not an event of 'BaseClass'"

[...]
AddHandler cbx, AddressOf cbxLookup_SelectedIndexChanged


\\\
AddHandler _
cbx.SelectedIndexChanged, _
AddressOf cbxLookup_SelectedIndexChanged
///
colLookups.Add(cbx)


--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.