CloneTreeView

5 posts, 0 answers
  1. Sanjay
    Sanjay avatar
    21 posts
    Member since:
    Jun 2014

    Posted 29 Jun 2015 Link to this post

    Hi

     

    Please advise how i can clone a tree view

     

    I have a radDropDownList and a RadTreeView.

    upon selection in the drop down, my data chages, though the table structure remain the same. Suppose i have options 1 and 2 in the drop down. user selects option 1 and tree is populated. User makes some selections in tree check boxes, then select option 2 from drop down list, new data populateed in tree view, and user does further selections in tree view. Now user goes back to option 1, i should get the tree view with data and tick selections

     below are my codes, but this does not seem to be good. tvNode is in designer

    local variables

            RadTreeView tvAsset = new RadTreeView();
            RadTreeView tvDriver = new RadTreeView();

            private void cbStruc_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
            {
                if (cbStruc.SelectedItem == null)
                    return;

                int i = 0;
                Image imagetemp;
                switch (cbStruc.SelectedItem.ToString())
                {
                    case "Assets":
                        if (tvAsset.Nodes.Count == 0)
                        {
                            TreeView tv = new TreeView();
                            new GroupMatrix().PopulateTreeCategories(tv, Globals.uLogin.lMatrix, cbStruc.SelectedItem.ToString());
                            tvNode.ClearSelection();
                            tvNode.DataSource = Globals.dtGMTreeCategory;

                            tvAsset = CloneTreeNodes(tvNode);
                        }
                        else
                        {
                            tvNode.ClearSelection();
                            tvNode = CloneTreeNodes(tvAsset);
                        }
                        break;

                    case "Drivers":
                        if (tvDriver.Nodes.Count == 0)
                        {
                            TreeView tv = new TreeView();
                            new GroupMatrix().PopulateTreeCategories(tv, Globals.uLogin.lMatrix, cbStruc.SelectedItem.ToString());
                            tvNode.ClearSelection();
                            tvNode.DataSource = Globals.dtGMTreeCategory;

                            tvDriver = CloneTreeNodes(tvNode);
                        }
                        else
                            tvNode = CloneTreeNodes(tvDriver);
                        break;

                }
                tvNode.ExpandAll();
            }

        private void cbStruc_SelectedIndexChanging(object sender, Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs e)
            {
                if (cbStruc.SelectedItem != null)
                    switch (cbStruc.SelectedItem.ToString())
                    {
                        case "Assets":
                            tvAsset = CloneTreeNodes(tvNode);
                            break;

                        case "Drivers":
                            tvDriver = CloneTreeNodes(tvNode);
                            break;

                    }
            }

            RadTreeView CloneTreeNodes(RadTreeView tvFrom)
            {
                RadTreeView treeview2 = new RadTreeView();
                if (tvFrom.Nodes.Count == 0)
                    return treeview2;

                foreach (RadTreeNode tn in tvFrom.Nodes)
                    treeview2.Nodes.Add((RadTreeNode)tn.Clone());
                
                treeview2.DataSource = tvFrom.DataSource;
                return treeview2;
            }


    Kindly advise

     

    Thank you

  2. Sanjay
    Sanjay avatar
    21 posts
    Member since:
    Jun 2014

    Posted 29 Jun 2015 in reply to Sanjay Link to this post

    Hello again

     I missed the following

                this.tvNode.DisplayMember = "GMDescription";
                this.tvNode.ParentMember = "ParentGMID";
                this.tvNode.ChildMember = "GMID";
                this.tvNode.ValueMember = "StrucID";

    now, in the checked nodes, how do i get the above value. they are all populated in the datasource.

    foreach (RadTreeNode rtn in myTV.CheckedNodes)
                {
                    rtn.??? does not have the relevant value, except for rtn.Value and rtn.Text
                }

     Thank you

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 02 Jul 2015 Link to this post

    Hi Sanjay,

    Thank you for writing.

    If I understand correctly by the value above you mean the value of the node in the tree which is one level higher than the current checked tree node. If this is the case you could directly access the parent, please see my code snippet below: 
    private void GetParentOfCheckedNode(RadTreeView radTreeView)
    {
        foreach (RadTreeNode node in this.radTreeView1.CheckedNodes)
        {
            if (node.Parent != null)
            {
                var value = node.Parent.Value;
                var dataBoundItem = node.Parent.DataBoundItem;
            }
        }
    }

    If you are still experiencing issues or I misunderstood you, please get back to me with additional information of what you are trying to accomplish.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Sanjay
    Sanjay avatar
    21 posts
    Member since:
    Jun 2014

    Posted 02 Jul 2015 in reply to Hristo Link to this post

    Hello. Thank you for replying

    I mentioned 2 issues above. let us address it 1 by 1.

    I attached a sample of my codes

    I have a radDropDownList and a RadTreeView. Upon radDropDownList change index, data in tree changes. On radDropDownList Asset selection, user checks "Naveo". Then user changes to radDropDownList Driver selection and selects "All"

    Now, if the user changes back to radDropDownList  Asset selection, the tree should show the Asset Data with the checked nodes ("Naveo)

     Finally, when show button is clicked, i should get StrucID for checked Assets and checked Driver

    Please rename to .zip. Also note that my subscription just expired and necessary is being done to renew

    Kindly advise 

    Thank you

     

  6. Hristo
    Admin
    Hristo avatar
    716 posts

    Posted 07 Jul 2015 Link to this post

    Hi Sanjay,

    Thank you for writing back.

    In your project, you are at one time manipulating the data source of the tree and at another removing RadTreeNodes. It is better that you choose one approach and stick with it. Considering you scenario, I believe that working only with the DataSource property should be enough.

    I created an example project with a sample implementation. Basically, you would need to store the checked nodes when changing the data source of RadTreeView. Besides the project, I am also sending you a gif file showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready