Home All Groups Group Topic Archive Search About
Author
8 Jan 2006 12:37 PM
guy
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

Author
8 Jan 2006 12:50 PM
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
----------------
Show quoteHide quote
"guy" <g**@discussions.microsoft.com> wrote in message
news:EAE22834-A933-400C-8A86-F2139F0A65AE@microsoft.com...
> 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
Author
8 Jan 2006 1:58 PM
guy
Thanks Ken.
I suspected as much, i wil have to do it the hard way then:(

cheers

guy

Show quoteHide quote
"Ken Tucker [MVP]" wrote:

> 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
> ----------------
> "guy" <g**@discussions.microsoft.com> wrote in message
> news:EAE22834-A933-400C-8A86-F2139F0A65AE@microsoft.com...
> > 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
>
>
>