Insted of TreeNodeCollection what can i use for RadTreeView in WPF

3 posts, 0 answers
  1. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 05 Aug 2014 Link to this post

    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. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 05 Aug 2014 in reply to Runjith Link to this post

    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

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 07 Aug 2014 Link to this post

    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.
     
Back to Top