I am trying to use an ArrayList, and bind it to a BindingList…
If I try to put it in (I have Option Strict On), I get a suggestion for casting that I implemented –
Yet I keep getting a runtime error no matter what I try.
Unable to cast object of type 'ArrayList' to type 'IList`
The code:
Dim myBoundList As System.ComponentModel.BindingList(Of something) =
New System.ComponentModel.BindingList(Of something)
(CType(myArrayList, System.Collections.Generic.IList(Of something)))
I have tried to insert .ToArray…
The accepted answer at the link https://stackoverflow.com/a/8770832/1217150 does exactly the same thing (even though the intent is the opposite), and I have tried it… (I mean, creating an IList item, and assigning
IList iList = new ArrayList();
It gives me the same error…
I am using VB.NET, but c# would help too. Please help. Thank you.
You should check out using the generic
Listclass (a .NET type) rather than using the non-genericArrayList. I suspect this might be related to your problem. It’s probably trying to cast the non-genericArrayListto anIList<T>(the generic version of IList).