Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I clone an IList data to another Ilist (Shallow copy).
Here is my code:
C#
IList lstOldList = null;
IList lstNewList;
Datagrid myDatagrid = some value;
lstOldList = myDatagrid.SelectedItems;

lstNewList = shallow copy of lstOldList ;
Any idea how to do this?
Posted
Updated 28-Dec-10 18:49pm
v2

1 solution

Import System.Linq into your class file.

And try the below:

C#
lstNewList = lstOldList.ToList();


The above code will work only if you have LINQ referred in your project.

Else, you need to loop through each item in the lstOldList and add it into the lstNewList.
 
Share this answer
 
Comments
vivektp 29-Dec-10 4:37am    
ToList is not available... so i used 2nd option. its working... thnx..
fjdiewornncalwe 30-Dec-10 12:43pm    
Have a five from me. Excellent answer.
Sergey Alexandrovich Kryukov 2-Mar-11 3:53am    
I agree, my 5
--SA
Jodi Munn 15-Mar-11 14:29pm    
Worked perfect for me! Thanks! my 5
Venkatesh Mookkan 16-Mar-11 0:31am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900