I'm try to improve our dynamic reporting system. I would like to add event handle to the object I've dynamically created on the form. One of the functions of this would be to populate a listbox from what was selected in the first listbox. i.e. The user select a town and the second listbox is populated by all the people living in that town.
The objectaction and objectactionfunction would be stored in a SQL table in the system. I would also like to store the objectactionfunction code in the table and dynamically create it at runtime. I've been looking into CodeDOM. Am I looking in the right direction. Pseudocode below
dim objectaction as string
dim objectactionfunction as string
objectaction = "LostFocus"
objectactionfunction =" "
addHandler textbox1.objectaction, addressof objectactionfunction
Here is an example of using Reflection to register an event handler using
Strings
to specify the event name and the event handler name:As I said in my comment, the code is rather verbose but that's the way it goes. Here's an extension method that you can use to write code once and use it wherever you like:
Sample usage: