473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

event-handling subs running twice in derived class.

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!

*** Sent via Developersdex http://www.developersdex.com ***
Nov 30 '05 #1
3 1457
>Any ideas?

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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 30 '05 #2
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.

"johncee" <jo*****@devdex.com> wrote in message
news:ed*************@TK2MSFTNGP09.phx.gbl...
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!

*** Sent via Developersdex http://www.developersdex.com ***

Nov 30 '05 #3

Thank you very much. -- This fixed it (as you knew it would)!
*** Sent via Developersdex http://www.developersdex.com ***
Nov 30 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2720
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
6
14879
by: rich_poppleton | last post by:
Help.... I've got a textarea where people type in a description. However for certain reasons we need to stop them typing !$*^ . I have a solution this which works fine in IE: function...
6
1864
by: vbMark | last post by:
If I have a control, for example a CheckedListBox, how do I add and event to code, for example that a box has been checked by the user? Thanks
15
21328
by: prabhdeep | last post by:
Hi, Can somebody explain, why in following code, i get "event not defined" error funcTest(sMenu) { doument.getElementById('id1').addEventListener('mousedown', function(){ click(sMenu,...
0
1820
by: lechatthierry | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
1
1944
by: Neko | last post by:
Is it possible to block a mouse event on an Hyperlink with a general script event? This is quite troublesome for me. I am trying to find a way to block the windows shortcut SHIFT + MOUSE LEFT...
6
28099
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
19
4722
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
1
2502
by: tdan | last post by:
I do not know how to get Event.stopObserving() to work in the context I am using it. I am displaying a Color Selection Table and attaching 2 events: 1. onmouseover to display the color to the user...
4
237
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: ...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.