0
votes

I have a made a custom datagridview with custom column objects. One of the columns in an edit button column which has a text box and a button to the right of it. This is a user control. What I am having problems with is when the user presses the button on the control I want an event to be raised on the datagridview which contains this column. I am doing this in winforms and vb.net. If anyone knows how to raise an event from the user control column which has the button to the datagridview which contains the column then it would be greatly appreciated.

Thanks

1
Do you want the event handler directly on the DataGridView, or do you want to add it in the Form's code ?Luc Morin
Thanks for asking I want it in the form's code.Gregory Williams

1 Answers

3
votes

In your custom control, simply declare an event that the control will raise:

Public Class MyUserControl

    Public Event MyEvent as EventHandler

...

   'Somewhere in you user control code, you want to raise the event
    RaiseEvent MyEvent(Me, EventArgs.Empty) 'using empty args for demo purposes

End Class

Then, in your form, you simply declare an event handler as usual:

Private Sub MyUserControl_MyEvent(sender as Object, e as EventArgs) Handles MyUserControl.MyEvent

... 'Whatever you need to do in reaction to the event

End Sub

Hope this helps