One More Question

C

Chuck Cobb

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
- INotifyPropertyChanged
- IEditableObject

- Class ClientList defines a collection of ClientInfo objects
- ClientList is Inherited from BaseList that defines some basic list methods and interfaces such as:
- IBindingListView
- IRaiseItemChangedEvents
- 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<BaseInfo> // a general control that supports all business objects, and

CtlClients : CtlDataGrid<ClientList> // 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<BaseInfo> in order to use it as parameter 'T' in the generic type or method CtlDataGrid".

ClientList is inherited from BaseList<ClientInfo> and ClientInfo is inherited from BaseInfo so I'm surprised that the compiler is not able to convert ClientList into BaseList<BaseInfo>. 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
 
N

Nick Malik [Microsoft]

I don't have VStudio in front of me, but considering the relationships you mentioned, you should be able to define your types as such:

CtlDataGrid<T> : CtlBase where T : BaseList // a general control that supports all business objects, and

CtlClients : CtlDataGrid<ClientList> // a specific control for clients that is inherited from the above


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer helping programmers.
--
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
- INotifyPropertyChanged
- IEditableObject

- Class ClientList defines a collection of ClientInfo objects
- ClientList is Inherited from BaseList that defines some basic list methods and interfaces such as:
- IBindingListView
- IRaiseItemChangedEvents
- 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<BaseInfo> // a general control that supports all business objects, and

CtlClients : CtlDataGrid<ClientList> // 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<BaseInfo> in order to use it as parameter 'T' in the generic type or method CtlDataGrid".

ClientList is inherited from BaseList<ClientInfo> and ClientInfo is inherited from BaseInfo so I'm surprised that the compiler is not able to convert ClientList into BaseList<BaseInfo>. 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top