Here's one more question on this topic:
I am developing a CRM system using business objects...I have used the
approach we previously discussed to develop lists of business objects for
the application and it works great! For example,
- Class ClientInfo defines a business object for a Client
- ClientInfo is inherited from BaseInfo which defines some basic item
methods and interfaces such as
- INotifyProperty Changed
- IEditableObject
- Class ClientList defines a collection of ClientInfo objects
- ClientList is Inherited from BaseList that defines some basic list
methods and interfaces such as:
- IBindingListVie w
- IRaiseItemChang edEvents
- IEditableObject
The problem I'm trying to resolve now has to do with Control binding...At
the moment, I have individual controls and datagrids bound directly to each
collection of business objects. For example, CtlClients has a datagrid that
is bound to the ClientList collection above and other business objects are
bound to other controls.
I would also like to use generics in the controls so that I can move some of
the common routines into a base control that the other controls inherit
from. What I would like to have is something like this:
CtlDataGrid<T> : CtlBase where T : BaseList<BaseIn fo> // a
general control that supports all business objects, and
CtlClients : CtlDataGrid<Cli entList> // a specific control
for clients that is inherited from the above
When I define these controls in this way, I get an error message that says
"The type ClientList must be convertible to BaseList<BaseIn fo> in order to
use it as parameter 'T' in the generic type or method CtlDataGrid".
ClientList is inherited from BaseList<Client Info> and ClientInfo is
inherited from BaseInfo so I'm surprised that the compiler is not able to
convert ClientList into BaseList<BaseIn fo>. Do I need to write a custom
TypeConverter to accomplish that? I attempted to do that, but it didn't
seem to make any difference...
Thanks,
Chuck
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:eo******** ******@tk2msftn gp13.phx.gbl...
Chuck,
What I would like to be able to do is have
Collection<Ca ts> and Collection<Dogs > inherited from Collection<Anim als>
and
that is inherited from Collection<T> so that I can define some common
routines in Collection<Anim als>. Is there a way to do that?
No, but how about
class AnimalCollectio n<T> : Collection<T> where T : Animal {}
class DogCollection : AnimalCollectio n<Dog> {}
class CatCollection : AnimalCollectio n<Cat> {}
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.