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

Insted of TreeNodeCollection what can i use for RadTreeView in WPF

2 Answers 172 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Runjith
Top achievements
Rank 2
Runjith asked on 05 Aug 2014, 01:53 PM
While Migrating Winforms to WPF,Insted of "TreeNodeCollection" what Collection can i use for RadTreeView in WPF.Now I am getting error like"Cannot implicitly convert type System.Windows.form.TreeNode to Telaric.Windows.Controls.RadTreeView."

EX:

 private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes)
        {

            RadTreeView newTreeNode = treeNodes.Add(xmlNode.Name); Error:Cannot implicitly convert type System.Windows.form.TreeNode to Telaric.Windows.Controls.RadTreeView."

           foreach (XmlAttribute zzz in xmlNode.Attributes)
                {
                    ConvertXmlNodeToTreeNode(zzz, newTreeNode.Items);  Error:For this had some invalid arguments.
                }
       }
Please Help me ASAP.

Regards,
Ranjith

2 Answers, 1 is accepted

Sort by
0
Runjith
Top achievements
Rank 2
answered on 05 Aug 2014, 02:25 PM
Hi,

If i use ItemCollection i am getting Error Like:Cannot implisitly convert "int" to "Telerik.Windows.controls.RadTreeView".

Code:
        ConvertXmlNodeToTreeNode(XmlNode xmlNode, ItemCollection treeNodes)

        {
            RadTreeView newTreeNode = treeNodes.Add(xmlNode.Name);   //Cannot implisitly convert "int" to "Telerik.Windows.controls.RadTreeView".

Regards,
Ranjith

 
0
Martin Ivanov
Telerik team
answered on 07 Aug 2014, 02:09 PM
Hi Ranjith,

The RadTreeView control can work with most of the .NET collections (IEnumerable, IList, etc.). In order to populate the tree you can wrap the objects from your xml file into view models and pass them to the treeview's ItemsSource property. Each object that is in the ItemsSource collection of the treeview will be wrapped into RadTreeViewItem when the tree is loaded.

If you want to populate the control with RadTreeViewItems directly you can use the Items collection of the tree and the Items collection of the RadTreeViewItems. In general the RadTreeView can be populated with RadTreeViewItems. Those items are the WPF alternative for the winforms'  TreeNode class. Note that each RadTreeViewItem has an Items collection itself, which holds the item's children.

Let us take the following tree for example:
-Item 1
   -Item 1.1
   -Item 1.2
-Item 2
   -Item 2.1

The hierarchy in the RadTreeView will be the following:
<telerik:RadTreeView>
    <telerik:RadTreeViewItem Header="Item 1" >
        <telerik:RadTreeViewItem Header="Item 1.1" />
        <telerik:RadTreeViewItem Header="Item 1.2" />
    </telerik:RadTreeViewItem>
    <telerik:RadTreeViewItem Header="Item 2" >
        <telerik:RadTreeViewItem Header="Item 2.1" />
    </telerik:RadTreeViewItem>
</telerik:RadTreeView>

You can take a look at the Populating with Data section in our help that demonstrates several approaches that can be used to populate a RadTreeView. In addition I attached a project that demonstrates populating a RadTreeView from XML file.

Please let me know if this helps.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TreeView
Asked by
Runjith
Top achievements
Rank 2
Answers by
Runjith
Top achievements
Rank 2
Martin Ivanov
Telerik team
Share this question
or