I need some help.
I'm creating an application where I add control on runtime to a form. This works fine and I can set all the properties I want. But my problem is how to add a procedure to those controls. I have several controls using the same procedure for handling some specific events (e.g. MouseUp, MouseDown).
Can somebody provide a sample or some hints how to solve this

Adding an eventhandler to a control created at runtime
srinu.net
hi
this code is ok for me. but my problem is different.
i have added the datagrid to my page dynamically and binding it to database.
and now i want to add an event like i want to sort the column by cllicking on the header.....so how do i add the event dynamically at the runtime
please help
sonali kedar
i didnt get the code u have given
so will u please write it more details please and for my problem please refer to reply i made
tHanks
sandy
blounsbury
In VB.net:
First, create a method to handle the event. In the case of MouseUp:
Private Sub MyControl_MouseUp(ByVal sender as Object, ByVal e as MouseEventArgs)
...
End Sub
Then when you create your control at runtime, simply wire up the event handler:
AddHandler MyControl.MouseUp, AddressOf MyControl_MouseUp
Tony
Ravi Teja
if you want to add a new event handler to your component do something like this:
myControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.myControl_MouseDown);
and then define your event handler:
private void myControl_MouseDown(object sender, MouseEventArgs e)
{
...
}
clovernet
Thanks a lot, this works perfect.
Regards,
Simon