lundi 13 juillet 2020

Add delegate to instance of type

I'm using reflection to reference a private control within a form. The type is called a GridViewManager which is similar to a DataGridView, except with its own methods. Within the class there is no Event for RowAdded or ItemAdded, so I want to add a Delegate to the method "AddItem" which is part of the class so that I can perform code when an item is added. However, I only want to do this for the active control that I'm referencing.

MethodInfo allFileInfo = typeof(grid).GetMethod("AddItem", BindingFlags.NonPublic | BindingFlags.Instance);```

*im aware typeof only excepts Types as arguments but this is kind of the idea




Aucun commentaire:

Enregistrer un commentaire