Is there a way to change the type of a form property after decleration of it?
I have a form class using myTypedTableAdapter1 bound to a form property ;
private myTypedTableAdapter1 this.tableadapter;
..
this.tableadapter = new myTypedTableAdapter1();
..
On the otherhands, I have two different menu items,
first creating an instance of this form with myTypedTableAdapter1 (as it is),
second creating an instance of this form with myTypedTableAdapter2 (with a different typed table adapter)
My problem is : How can I change the type of this.tableadapter from myTypedTableAdapter1 to myTypedTableAdapter2, during creating an instance of the form or in the Constructor/Load event of the form?
Help please!
[675 byte] By [
Ostenda] at [2007-12-16]
You would have to declare the variable as being of a type that both the desired types are derived form. For instance, if you declare a variable as being of type Object, you can then assign any type to it that is derived from the Object class, which means everything. You would want to keep the possible range of types as narrow as possible, so you would use the closest common ancestor of both classes. This means that if both classes are derived directly from the TableAdapter class then you should declare your variable as being of type TableAdapter. Because any instance of either of your classes IS a TableAdapter, the variable will accept either. Keep in mind, though, that you will have to cast the object as the correct type to use any members specific to that type.