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

Add RadTreeNode to multiple RadTreeViews

1 Answer 81 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Xavier Hutchinson
Top achievements
Rank 2
Xavier Hutchinson asked on 04 Mar 2010, 06:52 AM

Hi,

I have some code that generates a tree of nodes and then adds them to a supplied RadTreeView, however it seems that the built Tree of RadTreeNode isnt able to be added to more than one RadTreeView.

I wanted to display it in multiple TreeViews without having to create a new Tree of RadTreeNode for each one as it can be taxing on my SQL server and client Processing.

Thanks,

Xavier.


(The TreeView registering / unregistering methods are at the bottom.)
Apologies for the messy code file... its been a rush job and I havent cleaned up yet ^^

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
 
namespace Platform.Apps.Sigma  
{  
    public class SigmaObjectTree  
    {  
        public static Telerik.WinControls.UI.RadTreeNode BlankNode = new Telerik.WinControls.UI.RadTreeNode();  
 
        private List<Telerik.WinControls.UI.RadTreeView> TargetTreeViews = new List<Telerik.WinControls.UI.RadTreeView>();  
        private String UserNameFQN = String.Empty;  
 
        public Telerik.WinControls.UI.RadTreeNode Platform_Apps_Sigma_Node = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Infinity Σ (Platform.Apps.Sigma)",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.puzzle, 16, 16),  
            Tag = "" 
        };  
        public Telerik.WinControls.UI.RadTreeNode MySigmaNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "My Infinity",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.star_full48, 16, 16),  
            Tag = "",  
            Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)))  
        };  
        public Telerik.WinControls.UI.RadTreeNode EveryonesSigmaNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Everyone's Infinity",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.home, 16, 16),  
            Tag = "",  
            Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)))  
        };  
        public Telerik.WinControls.UI.RadTreeNode SystemSigmaNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Infinity Σ Settings",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.process, 16, 16),  
            Tag = "",  
            Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)))  
        };  
 
 
        public Telerik.WinControls.UI.RadTreeNode MySigma_UniqueProductsNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "My Unique Products",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.tools, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
        public Telerik.WinControls.UI.RadTreeNode MySigma_QuotationsNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "My Quotations",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.dollar_currency_sign, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
        public Telerik.WinControls.UI.RadTreeNode MySigma_OrdersNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "My Orders",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.shopping_cart, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
 
        public Telerik.WinControls.UI.RadTreeNode EveryonesSigma_UniqueProductsNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Everyone's Unique Products",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.tools, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
        public Telerik.WinControls.UI.RadTreeNode EveryonesSigma_QuotationsNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Everyone's Quotations",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.dollar_currency_sign, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
        public Telerik.WinControls.UI.RadTreeNode EveryonesSigma_OrdersNode = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Everyone's Orders",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.shopping_cart, 16, 16),  
            Tag = "",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
 
 
        public Telerik.WinControls.UI.RadTreeNode SystemSigma_Support = new Telerik.WinControls.UI.RadTreeNode()  
        {  
            Text = "Submit Feedback / Support Request",  
            Image = Platform.Resources.ResizeBitmap(Platform.Resources.red_flag, 16, 16),  
            Tag = "SIGMA_SETTINGS_SUPPORT",  
            ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))))  
        };  
 
 
        public Telerik.WinControls.UI.RadContextMenu Platform_Apps_Sigma_NodeContextMenu = new Telerik.WinControls.UI.RadContextMenu();  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_RefreshObjects = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Refresh Sigma Objects",  
            Tag = "SIGMA_SETTINGS_REFRESH_TREE",  
        };
        #region Unique Product Controls  
 
 
 
 
        public Telerik.WinControls.UI.RadContextMenu UniqueProductContextMenu = new Telerik.WinControls.UI.RadContextMenu();  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_MaintainUniqueProduct = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Maintain Unique Product",  
            Tag = "",  
        };  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_DeleteUniqueProduct = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Delete Unique Product",  
            Tag = "",  
        };  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_FindLinkedQuotesForUniqueProduct = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Find linked quotes for this Unique Product",  
            Tag = "",  
        };
        #endregion  
        #region Quotation Controls  
        public Telerik.WinControls.UI.RadContextMenu QuotationContextMenu = new Telerik.WinControls.UI.RadContextMenu();  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_MaintainQuotation = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Maintain Quotation",  
            Tag = "",  
        };  
        public Telerik.WinControls.UI.RadMenuItem rmi_SigmaObjectTree_DeleteQuotation = new Telerik.WinControls.UI.RadMenuItem()  
        {  
            Text = "Delete Quotation",  
            Tag = "",  
        };
        #endregion  
 
        #region Initializer Methods  
        public SigmaObjectTree(String _UserNameFQN)  
        {  
            UserNameFQN = _UserNameFQN;  
            InitializeComponent();  
        }  
        public void InitializeComponent()  
        {
            #region Event Handlers  
 
            rmi_SigmaObjectTree_RefreshObjects.Click += new EventHandler(rmi_SigmaObjectTree_RefreshObjects_Click);  
 
            rmi_SigmaObjectTree_DeleteUniqueProduct.Click += new EventHandler(rmi_SigmaObjectTree_DeleteUniqueProduct_Click);  
            rmi_SigmaObjectTree_FindLinkedQuotesForUniqueProduct.Click += new EventHandler(rmi_SigmaObjectTree_FindLinkedQuotesForUniqueProduct_Click);  
            rmi_SigmaObjectTree_MaintainUniqueProduct.Click += new EventHandler(rmi_SigmaObjectTree_MaintainUniqueProduct_Click);  
 
            rmi_SigmaObjectTree_MaintainQuotation.Click += new EventHandler(rmi_SigmaObjectTree_MaintainQuotation_Click);  
            rmi_SigmaObjectTree_DeleteQuotation.Click += new EventHandler(rmi_SigmaObjectTree_DeleteQuotation_Click);
            
            #endregion  
 
            #region Control assignments  
 
            Platform_Apps_Sigma_NodeContextMenu.Items.Add(rmi_SigmaObjectTree_RefreshObjects);  
 
            Platform_Apps_Sigma_Node.Nodes.Add(MySigmaNode);  
            Platform_Apps_Sigma_Node.Nodes.Add(EveryonesSigmaNode);  
            Platform_Apps_Sigma_Node.Nodes.Add(SystemSigmaNode);  
 
            MySigmaNode.Nodes.Add(MySigma_UniqueProductsNode);  
            MySigmaNode.Nodes.Add(MySigma_QuotationsNode);  
            MySigmaNode.Nodes.Add(MySigma_OrdersNode);  
 
            EveryonesSigmaNode.Nodes.Add(EveryonesSigma_UniqueProductsNode);  
            EveryonesSigmaNode.Nodes.Add(EveryonesSigma_QuotationsNode);  
            EveryonesSigmaNode.Nodes.Add(EveryonesSigma_OrdersNode);  
 
            SystemSigmaNode.Nodes.Add(SystemSigma_Support);  
 
            UniqueProductContextMenu.Items.Add(rmi_SigmaObjectTree_DeleteUniqueProduct);  
            UniqueProductContextMenu.Items.Add(rmi_SigmaObjectTree_FindLinkedQuotesForUniqueProduct);  
            UniqueProductContextMenu.Items.Add(rmi_SigmaObjectTree_MaintainUniqueProduct);  
 
            QuotationContextMenu.Items.Add(rmi_SigmaObjectTree_MaintainQuotation);  
            QuotationContextMenu.Items.Add(rmi_SigmaObjectTree_DeleteQuotation);
            #endregion  
 
            RefreshTreeviews();  
        }  
 
        public void RefreshTreeviews()  
        {  
            MySigma_UniqueProductsNode.Nodes.Clear();  
            EveryonesSigma_UniqueProductsNode.Nodes.Clear();  
 
            Platform.Apps.Sigma.UniqueProductsLibrary UPL = new Platform.Apps.Sigma.UniqueProductsLibrary(true);  
            var mine = (from q in UPL.UniqueProducts  
                        where q.CreatedBy == Environment.UserDomainName + @"\" + Environment.UserName  
                        orderby q.Created descending  
 
                        select q).Take(50);  
 
            foreach (Platform.Data.Linq.SigmaUniqueProduct u in mine.ToList())  
            {  
                MySigma_UniqueProductsNode.Nodes.Add(new Telerik.WinControls.UI.RadTreeNode()  
                {  
                    Text = u.ShortDescription,//.PadLeft(10) + "\r\n" + u.StockCode + "\r\n" + u.SysproStockCode.ShortDescription,  
                    Name = u.ID.ToString(),  
                    Tag = u,  
                    Image = Resources.ResizeBitmap(Resources.tools, 16, 16),  
                    ContextMenu = UniqueProductContextMenu,  
                    ToolTipText = "SIGMA_UNIQUEPRODUCT",  
                    Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)))  
                });  
            }  
 
            var everyones = (from q in UPL.UniqueProducts  
                             orderby q.Created descending  
                             select q).Take(50);  
 
            foreach (Platform.Data.Linq.SigmaUniqueProduct u in everyones.ToList())  
            {  
                EveryonesSigma_UniqueProductsNode.Nodes.Add(new Telerik.WinControls.UI.RadTreeNode()  
                {  
                    Text = "(" + Platform.Security.SecurityTools.WhoIs(u.CreatedBy) + ") " + u.ShortDescription.PadLeft(10),  
                    Name = u.ID.ToString(),  
                    Tag = u,  
                    Image = Resources.ResizeBitmap(Resources.tools, 16, 16),  
                    ContextMenu = QuotationContextMenu,  
                    ToolTipText = "SIGMA_UNIQUEPRODUCT",  
                    Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)))  
                });  
            }  
            Platform_Apps_Sigma_Node.ExpandAll();  
        }
        #endregion  
 
 
 
 
 
 
        #region Event Handler Methods  
 
        void TargetTreeView_DoubleClick(object sender, EventArgs e)  
        {  
            try 
            {  
                foreach (Telerik.WinControls.UI.RadTreeView TargetTreeView in TargetTreeViews)  
                {  
                    switch (TargetTreeView.SelectedNode.Tag.ToString())  
                    {  
                        case "SIGMA_SETTINGS_REFRESH_TREE":  
                            {  
                                RefreshTreeviews();  
                                break;  
                            }  
                        case "SIGMA_SETTINGS_SUPPORT":  
                            {  
                                System.Windows.Forms.Form GenericFormDlg = new System.Windows.Forms.Form();  
                                GenericFormDlg.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;  
                                GenericFormDlg.AutoSize = true;  
                                GenericFormDlg.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;  
                                GenericFormDlg.Text = "Submit new feedback / support request for Platform Apps";  
                                GenericFormDlg.Controls.Add(new Platform.UI.Windows.Common.UCPlatformAppFeedback(UserNameFQN));  
                                GenericFormDlg.ShowDialog();  
                                break;  
                            }  
                    }  
                }  
            }  
            catch 
            {  
 
            }  
        }  
 
        void rmi_SigmaObjectTree_RefreshObjects_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }  
 
        static void rmi_SigmaObjectTree_DeleteQuotation_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }  
 
        static void rmi_SigmaObjectTree_MaintainQuotation_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }  
 
 
        static void rmi_SigmaObjectTree_MaintainUniqueProduct_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }  
 
        static void rmi_SigmaObjectTree_FindLinkedQuotesForUniqueProduct_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }  
 
        static void rmi_SigmaObjectTree_DeleteUniqueProduct_Click(object sender, EventArgs e)  
        {  
            throw new NotImplementedException();  
        }
        #endregion  
 
 
 
        public bool RegisterRadTreeView(Telerik.WinControls.UI.RadTreeView RadTreeViewToAdd)  
        {  
            try 
            {  
                RadTreeViewToAdd.Nodes.Add(Platform_Apps_Sigma_Node);  
                RadTreeViewToAdd.DoubleClick += new EventHandler(TargetTreeView_DoubleClick);  
                TargetTreeViews.Add(RadTreeViewToAdd);  
                return true;  
            }  
            catch 
            {  
                return false;  
            }  
        }  
        public bool UnRegisterRadTreeView(Telerik.WinControls.UI.RadTreeView RadTreeViewToRemove)  
        {  
            try 
            {  
                RadTreeViewToRemove.Nodes.Remove(Platform_Apps_Sigma_Node);  
                RadTreeViewToRemove.DoubleClick -= new EventHandler(TargetTreeView_DoubleClick);  
                TargetTreeViews.Remove(RadTreeViewToRemove);  
                return true;  
            }  
            catch 
            {  
                return false;  
            }  
        }  
    }  
}  
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 04 Mar 2010, 08:45 AM
Hi Xavier Hutchinson,

Thank you for writing. By design RadTreeNodes are removed from their parent collection if they are added to another parent collection, and hence the only way to achieve this is to create new nodes.

Adding a node to multiple tree views is not possible because the nodes consist of a visual and a logical part, with the logical part tightly coupled to the RadTreeView control. Doing so, if it was possible, will result in visual state corruption and other strange behavior.

You will probably have to do an iteration over your application design in order to address this case appropriately.

We are ready to assist you should you have other questions.

All the best,
Victor
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.
Tags
Treeview
Asked by
Xavier Hutchinson
Top achievements
Rank 2
Answers by
Victor
Telerik team
Share this question
or