473,509 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copying a collection

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
Jan 8 '06 #1
2 1089
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" <gu*@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.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

Jan 8 '06 #2
guy
Thanks Ken.
I suspected as much, i wil have to do it the hard way then:(

cheers

guy

"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" <gu*@discussions.microsoft.com> wrote in message
news:EA**********************************@microsof t.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


Jan 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1523
by: Dan | last post by:
We debug a VB.Net App that uses compact framework to a DAP Windows CE.Net device. When I debug I would like to only have the EXE copied down. Right now it copies any referrences as well and...
3
2106
by: VM | last post by:
How can I copy the contents of one datatable to another datatable? I've already the source table so I only need to copy its rows. Thanks.
0
1213
by: San Diego Guy | last post by:
Hi all! I have Datagrid. Within that datagrid I have a drop down list that I set up some values in (a "collection") I set up an edit command column on the datagrid and wrote simple code to get...
2
2333
by: Carlos | last post by:
I have a dropdown list that binds data from a data reader bo I have a second dropdown list in my wen form which I want to have same data, how can I copy the one is bind to a secopnd one.. see my...
10
7803
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in...
2
886
by: Paul Bromley | last post by:
This may seem a stupid question, but is it possible to copy a file that is open? I have written an application to dispaly TIFF, RTF and other file formats. I now need to add a function that will...
7
5665
by: drawoh | last post by:
Hi All, I have a class that creates a thread, a mutex and a condition variable in its constructor. I am writing a copy constructor for this class in C++. I am doing a simple copy using the...
1
1368
by: shumaker | last post by:
If I create a new collection from a colelction containing only value types, will the value types be copied, or will both collections reference the same value types. Such as: new...
1
2783
by: RonLandreth | last post by:
I am writing an accounting system for a class I'm taking at SLU. I need help figuring out the best way to go about copying a 2D array to a temporary 2D array, for eventually copying it back. ...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.