Pass an event into a constructor

Posted by Vaccano on Stack Overflow See other posts from Stack Overflow or by Vaccano
Published on 2010-06-03T22:00:23Z Indexed on 2010/06/03 22:04 UTC
Read the original article Hit count: 151

Filed under:
|
|

I have a class that I want to be able the handle the mouse up event for a grid.

I tried to create it with a static method call like this:

MyDataBinding.BindObjectsToDataGrid(ListOfObjectsToBind, myGrid.MouseUp);

The end goal being that in the method I would assign a delegate to the MouseUp

PassedInMouseUp += myMethodThatWillHandleTheMouseUp;

Looks good here (to me) but the compiler chokes on the first line. It says that I can only use MouseUp with a += or a -=.

Clearly I am going about this the wrong way. How can I get a different class to handle the mouse up with out having to:

  • Pass in the whole grid
  • Expose the method that will be handling the mouse up as a public method.

Or, is this just a limitation and I will have to do one of the above?

© Stack Overflow or respective owner

Related posts about c#

Related posts about events