RSH wrote:
Quote:
My question is ... what is the syntax to "convert" dropdownlist1 from a
dropdownlist to my CustomDDL?
Short answer: You can't.
Longer Answer: You can't, and here's why.
The DropDownList class has a bunch of properties and methods.
Your CustomDDL, because it inherits from this, has /all/ of these, plus
any new stuff that you've added.
However, /because/ your CustomDDL has all the base class stuff, you can
"treat it as" a DropDownList, i.e. you can "up-cast" your control to
"get at" the base class functionality, as in
DirectCast( customDDL1, DropDownList ).whatever( ... )
The converse is /not/ True.
The DropDownList does /not/ have all the "stuff" that your customDDL
has, so you cannot "treat is as" one (i.e. you can't "down-cast" from
the base class to a subclass).
However ...
Object Variables are clever things these days. Not only can they hold
the /actual/ type that they are declared as, but they can hold an object
of any sub-class as well (because the subclass has /all/ the base class
stuff, plus bits, so can be "treated as" the base Type).
So, if in your base web page, you have
Protected WithEvents DropDownList1 as DropDownList
then there's nothing to stop you doing
MyBase.DropDownList1 = New CustomDDL
The base class is happy, because it has a reference to an object that it
can "treat as" a DropDownList, but when it tries to call, say, the
Render() method, it will be the /override/ of Render in your custom
subclass that actually gets called!
Welcome the Wonderful World of Polymorphism!
HTH,
Phill W.