Cannot Refer to an Instance member... Addhandler Issue

  • Thread starter Thread starter john
  • Start date Start date
J

john

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
 
john said:
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.
 
* "john said:
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.
 
Back
Top