copying a collection

G

Guest

how do i copy all items from a generic collection to a class that inherits
from a generic class *** within *** that class?

i have a class that inherits from BindingList and within it i have a method
that generates a List , perfoms operations on it, and then copies all its
elements into the inheriting class.
If this was outside the inheriting class i could use the overloaded
constructor which takes a Generic IList however i cant do this within the
class as it gives, understandably, "'Me' cannot be target of an assignment"

I dont really want to have to iterate through the List, copying each item in
but if all else fails i will have to.
my code (simplified) should look like this:-

Dim myList As New List(Of thing)

myList = New List(Of thing)(me)
MyList.Sort()

'i want to do something like:-
Me = New MyInheritedBindingList(Of thing)(myList) 'this line is
not allowed

'but it looks like i will have to do:-
Me.Items.Clear
For Each it as thing in myList
me.items.add(it)
next

guy
 
K

Ken Tucker [MVP]

Hi,

Some collection classes support addrange to add more than one item
at a time. The bindinglist(of T) does not support this so you will have to
add the items one at a time.

Ken
 
G

Guest

Thanks Ken.
I suspected as much, i wil have to do it the hard way then:(

cheers

guy
 

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