Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a event handler from another event?
Message
From
28/03/2008 23:29:54
 
 
To
28/03/2008 21:04:00
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01306622
Message ID:
01306666
Views:
4
Well thank you. Working with Foxpro, I never really worked in big teams on a given project. 2 others at the very most. Working in other tools, I've been involved in teams as big as 6 to 8 others. And seen several times, a small change cause a major regression bug in the software. Typically cause the way the system was tied together and the programmer who did the latest change didn't understand fully everything.

So it's always best to be as explicit as possible with your code for the next guy.

>I second that.
>
>>I prefer creating a totally separate method. If for no other reason then having other developers having to look at your code. Where I hopefully remember to do a search and find all references to a method call before modifying said method, I probably wouldn't remember to do a reference search on event handlers. So I could potentially break some things by modifying the event code.
>>
>>>Are you saying *not* to put the working code in one specific event handler and then have the other even handlers point to it, but rather, create a totally separate method, and make all even handlers point to that? Is that a more mature coding habit?
>>>
>>>
>>>
>>>
>>>>I've done this numerous times by making another method with the code. Then this method can get called by the various events that need to.
>>>>
>>>>>I have code in an event handler that I want to use by various events, but I seem to have an overlay mismatch problem...
>>>>>
>>>>>The object is a DataGridView, and the working code is presently in the form.CellClick() event handler, like this:
>>>>>
>>>>> private void mmGridCustomers_CellClick(object sender, DataGridViewCellEventArgs e)
>>>>> {
>>>>> string CustNo = this.mmGridCustomers.GetCurrentRowPK().ToString();
>>>>> this.Job.GetJobsByCustNo(CustNo);
>>>>> }
>>>>>
>>>>>Now, I want to activate this same event handler code with another event of the grid, which is the RowHeaderMouseClick() event. In other words, I want the same thing to happen with each of these two possible user actions.
>>>>>
>>>>>In the Poperties page of the form designer IDE, when trying to assign the existing event handler to the RowHeaderMouseClick(), I noticed that the existing event handler does not appear in the dropdown list to choose from, and I guess I have figured out that it is becuase the two events have different "signatures" (is that how you say it?) because they have different parameters or overloads?
>>>>>
>>>>>So, I am presently doing this trick of just passing null values to the target event handler, since the parameters are not used in the method code anyway:
>>>>>
>>>>> private void mmGridCustomers_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
>>>>> {
>>>>> this.mmGridCustomers_CellClick(null,null);
>>>>> }
>>>>>
>>>>>
>>>>>It works, but is this a good practice, or is there a better or more proper way to handle this?

(On an infant's shirt): Already smarter than Bush
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform