Inheritance/Event Firing

C

crk2

Here a simple one. (At least I think it is?) and any help would be truly
appreciated.

I have an inherited textbox on my form based on a custom texbox control. It
looks something like this (I'll keep it simple)

Base Class:
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
MsgBox("In the class")
End Sub

Inherited Object (on the form):
Public Sub TextBoxBase1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBoxBase1.TextChanged
MsgBox("In the form")
End Sub


I want to see how I can prevent the base classes ontextchanged event from
firing and override the base's code and handle everything on the form. I'm
sure it's probably a simple question, but for a fairly new .net'er , it got
me stumped...
 
H

Herfried K. Wagner [MVP]

Hello,

crk2 said:
Here a simple one. (At least I think it is?) and any help would be truly
appreciated.

I have an inherited textbox on my form based on a custom texbox control. It
looks something like this (I'll keep it simple)

Base Class:
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)

Remove the line above.
MsgBox("In the class")
End Sub

Inherited Object (on the form):
Public Sub TextBoxBase1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBoxBase1.TextChanged
MsgBox("In the form")
End Sub

I want to see how I can prevent the base classes ontextchanged event from
firing and override the base's code and handle everything on the form. I'm
sure it's probably a simple question, but for a fairly new .net'er , it got
me stumped...

See inline comment.

Regards,
Herfried K. Wagner
 
T

Tom Spink

The base's OnTextChanged method will raise the event, so you don't want to
be doing that. Take out MyBase.OnTextChanged(e)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
C

crk2

Thanks for assistance, but I am still running into a wall. (I guess you
could blame it on my ignorance). So I applogize in advance for drilling down
deaper into this one.

If I remove the MyBase.OnTextChanged(e) then wouldn't the base class be
raised rather then the form's event? I guess what I am trying to do (10,
000 foot view) is to have a generic routine in the base class that handles
my dataset updates. Let's say in the textbox_leave event of the base class.
However, I only want this event to be raised when control validation (on the
inherited form) has been performed. Let's say that this is done on the
inherited control. Something like this:


On the form: (I'll keep it simple again)
Private Sub TextBoxBase1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBoxBase1.Leave
'Handle control validaion (I.e. not empty or check if the text changed)
'If we pass then call then raise the base event to update the dataset
'else get the heck outta here
End Sub

Base class:
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
'perform the update
End Sub

Thanks again
Regards
-Chris
P.S. In VFP I've worked with nodefault/dodefault to handle situations like
these. A simple nodefault --> run my validation --> dodefault() would do the
trick.
 
T

Tom Spink

I have no idea what nodefault, my validation, dodefault does. But, a guess
at what they do, says that you should be doing this:

<WatchForWrapping>

Protected Overrides Sub OnLeave(ByVal e as System.EventArgs)
' Do your Validation
' Now run the Base Class:
MyBase.OnLeave(e)
End Sub

</WatchForWrapping>

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit
 
C

crk2

Thnks Tom. I won't bore you with the details of the dodefault/nodefault and
VFP events. You put me on the right track though and I'll continue to look
into your suggested steps, but I ended up using a switch (via a property) to
determine if the even should being raised. Looks like its doing the trick.
(albiet, it may be a temporary workaround) until I can get a handle on my
event raising qaundry.

Thanks again Tom
Regards
Chris
 
H

Herfried K. Wagner [MVP]

Hello,

crk2 said:
my dataset updates. Let's say in the textbox_leave event of
the base class.
However, I only want this event to be raised when control
validation (on the inherited form) has been performed. Let's say
that this is done on the inherited control. Something like this:


On the form: (I'll keep it simple again)
Private Sub TextBoxBase1_Leave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBoxBase1.Leave
'Handle control validaion (I.e. not empty or check if the text changed)
'If we pass then call then raise the base event to update the dataset
'else get the heck outta here
End Sub

Base class:
Protected Overrides Sub OnLeave(ByVal e As System.EventArgs)
'perform the update

\\\
If <validation successful> Then
MyBase.OnLeave(e)
End If
///

Regards,
Herfried K. Wagner
 

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