Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more:
Hi I have a Push button:
void grdctrl_Grid_Prop_PushButtonClick(object sender, GridCellPushButtonClickEventArgs e)
{
}

and I need some other event from other controls to be called upon pressing the push button. The method for that event is:

private void Hidden_drgdrp_Prop_DragDrop(object sender, DragEventArgs e)
        {
        }
        }

None of these controls are the standard controls, and both are the user controls(but black box, no acess to their source).
So, I am looking for a way to raise an event(and consequently Hidden_drgdrp_Prop_DragDrop method) programmitically in my pushbutton click method.
Is their a general method to raise any event(with different EventArgs)Programmatically?
Posted

i got 2 solutions in code project for raising an event Programmatically,
raising an event programmatically[^]
How to call "click on column header" event programmatically?[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Dec-11 15:08pm    
That is correct, a 5.
Please see the rational and clarification in my answer.
--SA
theanil 25-Dec-11 11:22am    
Thanks -SA
Monjurul Habib 23-Dec-11 15:39pm    
5!
theanil 25-Dec-11 11:22am    
Thanks
Try Hidden_drgdrp_Prop_DragDrop(sender,new DragEventArgs() );
 
Share this answer
 
In clarification of other answers:

The event objects have a number of limitations compared to delegate instances used directly. One important limitation is: there is only one way to invoke an event: in the code of the class where the event instance is declared. It is not possible to invoke a event from anywhere else, not even from a derived class, not from a different instance of the same class, regardless to access modifiers or anything else. This is just not allowed.

This limitation does not apply to regular delegate instances used directly, but doing so from other classes or different instances through direct access to a delegate instance would be bad programming practice. That said, this limitation for event is designed for a good reason, as an important fool-proof measure.

By this reason, you should not even try to find any work-around to invoke an event outside its declaring class and its instance, and not try to apply equivalent technique through delegate instances. Instead, you should "move you logic". You should create a separate method to be used in two or more places of you program: one place is a call from the event handler, another one — from somewhere else.

—SA
 
Share this answer
 
v5
Comments
Monjurul Habib 23-Dec-11 15:39pm    
nice detail always...5!
Sergey Alexandrovich Kryukov 23-Dec-11 15:40pm    
Thank you, Monjurul.
--SA
theanil 25-Dec-11 11:24am    
Nice Answer -SA
5+
Sergey Alexandrovich Kryukov 25-Dec-11 12:21pm    
Thank you, Anil.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900