SortedBindingLists with InterfacesSortedBindingLists with Interfaces
Old forum URL: forums.lhotka.net/forums/t/7931.aspx
Wbmstrmjb posted on Monday, November 02, 2009
Running into an issue with SBLs and Interfaces. I have an Interface for an Editable Collection that has a SortedBindingList as a property:
(I replaced lessthan/greaterthan with ^ because forum doesn't like carrots)
interface IClassA {
SortedBindingList^IClassAChild^ Sorted {get;}
}
interface IClassAChild {
// blah
}
In the implementation, the SortedBindingList won't take the implementing object's type without blowing up:
SortedBindingList^IClassAChild^ sorted = new SortedBindingList^IClassAChild ^((System.Collections.Generic.IList^ IClassAChild^)this); // COMPILES BUT BLOWS UP AT RUNTIME
How else can I implement an SBL (or any sort for that matter) on my object which returns either itself sorted, or a List of IClassAChild?
RockfordLhotka replied on Monday, November 02, 2009
Can you provide the exception detail?Wbmstrmjb replied on Monday, November 02, 2009
System.InvalidCastException : Unable to cast object of type 'Cap.BusinessObjects.FacilityMaint.DismantlerContractAmendmentList' to type 'System.Collections.Generic.IList`1[Cap.BusinessObjects.FacilityMaint.IContractAmendment]'.
In this case, IContractAmendment would be IClassAChild in my example and DismantlerContractAmendmentList iimplements IClassA.
Happens on the instantiation of the SortedBindingList.Copyright (c) Marimer LLC