Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calling a event handler from another event?
Message
De
29/03/2008 12:31:22
 
 
À
29/03/2008 00:55:41
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01306622
Message ID:
01306730
Vues:
3
As I'm sure you found out thou, that window doesn't even have to be 3 yrs. And then you feel really stupid going to users and telling them you're trying to understand what you did 6 months ago.

Do that enough times and you start changing your programming habits a bit.

>I usually program alone... I always try and code like I'm in a large team.
>
>Why...
>
>3 years later... I'm that next guy your talking about and I want to be able to figure out what the !#@%$ I was thinking when I coded that! <g>
>
>
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform