event-handling subs running twice in derived class.

  • Thread starter Thread starter johncee
  • Start date Start date
J

johncee

Greetings,

I created a base class that has a datagrid. I've made it generic as
possible so that any derived classes pass some info to the base
constructor (including a SQL select stmt) & through the base class, any
db table can be displayed/maintained in the grid.

I've made some of the base class' event-handling subs overridable and in
some of the derived classes using the base, the subs are being
overridden:

Public Overrides Sub ToolBar1_ButtonClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles
ToolBar1.ButtonClick

Overrides... "Handles Toolbar1.buttonClick" - My problem is that when
any button on the toolbar is clicked via a project with the derived
class, the sub in the derived class is called twice in a row. I've
gotten around this problem with a kludgy global variable that detects
the second consecutive call, but I don't like it and I know I must be
doing something wrong. It's not just the toolbar button click event but
apparently any overriding event-handling sub gets called (from the
derived class) twice.

Any ideas?

THANK YOU!
 
Any ideas?

Removes the Handles clause on the overriding method. You only need it
on the base method.


Mattias
 
Take off the 'handles' part. That hooks it up twice, once in the base class,
and once in the inheriting class.

Use AddHandler in the base class to attach the handler to the method. If it
happens to be a derived class that overrides this method, then it will
attach to the appropriate version.
 
Back
Top