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

Cannot Refer to an Instance member... Addhandler Issue

P: n/a
OK,

The problem isn't with Addhandler, it's with my
understanding of Shared...

I add a handler like this:
AddHandler ct.ColumnChanged, New _
DataColumnChangeEventHandler(AddressOf OnColumnChanged)
from within a Private Sub.

My handler is defined as:
Private Shared Sub OnColumnChanged(ByVal sender As _
Object, ByVal args As DataColumnChangeEventArgs)

When I attempt to set the state of a button in my form
using the
syntax "<squiggle>me.btnUpdate<squiggle>.Enabled = True"

I receive this error:
Cannot refer to an instance member from within a shared
member initializer without an explicit instance of the
class.

Isn't the button on my form an explicit instance of a
class?

Am I trying to do something that doesn't make sense?
Should I be reading up on Object references?

I sure would appreciate some insights. While I'm out here
I'll try to answer a couple of questions myself.

Thanks,

John

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


P: n/a
"john" <jo*********@whizkidcomputing.cm> schrieb
OK,

The problem isn't with Addhandler, it's with my
understanding of Shared...

I add a handler like this:
AddHandler ct.ColumnChanged, New _
DataColumnChangeEventHandler(AddressOf OnColumnChanged)
from within a Private Sub.

My handler is defined as:
Private Shared Sub OnColumnChanged(ByVal sender As _
Object, ByVal args As DataColumnChangeEventArgs)

When I attempt to set the state of a button in my form
using the
syntax "<squiggle>me.btnUpdate<squiggle>.Enabled = True"

I receive this error:
Cannot refer to an instance member from within a shared
member initializer without an explicit instance of the
class.

Isn't the button on my form an explicit instance of a
class?

Am I trying to do something that doesn't make sense?
Should I be reading up on Object references?

I sure would appreciate some insights. While I'm out here
I'll try to answer a couple of questions myself.

Which instance of the Form should be accessed in the shared sub? Maybe there
is none, one or there are multiple instances.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
* "john" <jo*********@whizkidcomputing.cm> scripsit:
The problem isn't with Addhandler, it's with my
understanding of Shared...

I add a handler like this:
AddHandler ct.ColumnChanged, New _
DataColumnChangeEventHandler(AddressOf OnColumnChanged)
from within a Private Sub.

My handler is defined as:
Private Shared Sub OnColumnChanged(ByVal sender As _
Object, ByVal args As DataColumnChangeEventArgs)

When I attempt to set the state of a button in my form
using the
syntax "<squiggle>me.btnUpdate<squiggle>.Enabled = True"

I receive this error:
Cannot refer to an instance member from within a shared
member initializer without an explicit instance of the
class.

Isn't the button on my form an explicit instance of a
class?

Am I trying to do something that doesn't make sense?
Should I be reading up on Object references?

I sure would appreciate some insights. While I'm out here
I'll try to answer a couple of questions myself.


What's your intention of declaring the handler as 'Shared'? The
'Shared' keyword means that the procedure is shared between all
instances of the form class in your case. The control/class you add the
handler to is an instance object, it's not shared between all instances
of the form/class.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.