Generics, Inheritance, and the SortedBindingList

Generics, Inheritance, and the SortedBindingList

Old forum URL:

bgilbert posted on Friday, January 08, 2010

In version 1 of my app, I have a subclass of BusinessBase and BusinessListBase called ProductionOrder and ProductionOrders. In my UI, I create a SortedBindingList using these as parameters. Everything works great.

Now in version 2 of my app, I need to subclass ProductionOrder (let's call it ProductionOrderSub). Apparently, I don't need to refactor the ProductionOrders class to use it to contain a collection of ProductionOrderSub objects. It accepts it because ProductionOrderSub is a ProductionOrder. Everything compiles just fine.

Now I get to the UI and try to instantiate a SortedBindingList using my new subclass like this:
Dim mySBL as New SortedBindingList(Of ProductionOrders, ProductionOrderSub)

The compiler complains that "Type argument 'ProductionOrders' does not inherit from or implement the constraint type 'System.Collections.generic.IList(Of ProductionOrderSub)"

(I should also mention that I have my own subclasses of all three CSLA base classes. Not sure if it's pertinent.)

Here's where I get pretty lost. Do I need to create a new collection class that only accepts my new subclass as a parameter? I'm obviously no expert in Generics and I feel quite confused.

Thanks for any help.

RockfordLhotka replied on Friday, January 08, 2010

SortedBindingList only takes one type parameter, not two.

SBL(Of T) is just a view over an IList(Of T) - and in both cases the T is the type of the item contained in the list.

Copyright (c) Marimer LLC