|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
copying a collectionfrom 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 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 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 > > >
2 keys pressed at once
Namespace around API calls Virtual Serial Port Bluetooth System.IO.Ports .Net 2.0 - Webbrowser control flickering on resize.... Loading UserControl on a ShowDialog Form sequence strange rotate gdi object Access SubQuery Help Needed..................... VS2005 combox question ListView vs. ListBox in my Program bindaing a DATE field |
|||||||||||||||||||||||