473,569 Members | 3,063 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_Button Click(ByVal sender As
System.Object, ByVal e As
System.Windows. Forms.ToolBarBu ttonClickEventA rgs) Handles
ToolBar1.Button Click

Overrides... "Handles Toolbar1.button Click" - 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 1463
>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******** *****@TK2MSFTNG P09.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_Button Click(ByVal sender As
System.Object, ByVal e As
System.Windows. Forms.ToolBarBu ttonClickEventA rgs) Handles
ToolBar1.Button Click

Overrides... "Handles Toolbar1.button Click" - 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
2724
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
14897
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 keypress() {
6
1868
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
21340
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, event); }, false); }
0
1828
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 BUTTON that open the Hyperlink in a new window for a Web application. I just want to capture the Shift click event and prevent it from opening a new...
1
1945
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 BUTTON that open the Hyperlink in a new window for a Web application. I just want to capture the Shift click event and prevent it from opening a new...
6
28114
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 RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the...
19
4733
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 DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
1
2512
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 2. onmouseup to select the color and hide the Table The onmouseup event should also call Event.stopObserving() so that mouse clicks are no...
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: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5228
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.