This is a migrated thread and some comments may be shown as answers.

Cannot implicitly convert type 'System.Collections.Generic.IList<Telerik.Web.UI.RadTreeNode>' to 'System.Collections.ArrayList'. An explicit conversion exists (are you missing a cast?)

3 Answers 774 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vijay
Top achievements
Rank 1
Vijay asked on 03 May 2010, 05:57 PM

protected

 

Telerik.Web.UI.RadTreeView TopicsTree;

 


I need to store checked nodes for a RadTreeView into an arraylist. But when I do that like below:

ArrayList

 

checkedTopics = TopicsTree.CheckedNodes;

 

I get the error  'Cannot implicitly convert type 'System.Collections.Generic.IList<Telerik.Web.UI.RadTreeNode>' to 'System.Collections.ArrayList'. An explicit conversion exists (are you missing a cast?)'.

Please help

3 Answers, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 04 May 2010, 09:54 AM
Hello Vijay,

There is an explicit conversion. You just need to get the IList Collection (inherits the ICollection) from the RadTreeNodeCollection and to add it to the arrayList (as "AddRange" preferably, becuse if you just use "Add", you need to iterate through the collection - this makes your code to look bad).

Here is a short example of how it should be done:
ArrayList arrayList = new ArrayList();
arrayList.AddRange(RadTreeView1.CheckedNodes.ToList());

Hope this will help you!

Kind regards,
Nikolay Tsenkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Vijay
Top achievements
Rank 1
answered on 06 May 2010, 05:37 PM
Nikolay,

I did follow your example :

arrayList.AddRange(RadTreeView1.CheckedNodes.ToList());

But in my code, I am not getting the method ToList for CheckedNodes so it is giving me Error -  'System.Collections.Generic.IList<Telerik.Web.UI.RadTreeNode>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Collections.Generic.IList<Telerik.Web.UI.RadTreeNode>' could be found.

Please help me!
0
Nikolay Tsenkov
Telerik team
answered on 07 May 2010, 01:45 PM
Hi Vijay,

This method is being rolled out in the 3.5 version of .NET framework. If you don't have the method than you are probably building over .NET 2.0.
Please check that out.

For now you can simply do a foreach on the CheckedNodes collection and to add all the items (refs to them)
to the arrayList. This should work.

Hope this will help you!


Regards,
Nikolay Tsenkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Sachita
Top achievements
Rank 1
Iron
Iron
Iron
commented on 04 Jan 2022, 04:26 AM

Can anyone provide sample code ,even i have same issue

 

Tags
TreeView
Asked by
Vijay
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Vijay
Top achievements
Rank 1
Share this question
or