/// <summary> /// Load a treeview structure from a xml file. /// </summary> /// <param name="fileName">File path of the xml file.</param> public void LoadFromXml(string fileName) { TextReader reader = new StreamReader(fileName); XmlSerializer serializer = new XmlSerializer(typeof(ActiveUp.WebControls.Nodes)); ActiveUp.WebControls.Nodes nodes = (ActiveUp.WebControls.Nodes)serializer.Deserialize(reader); reader.Close(); if (nodes.NodesList.Count > 0) { foreach (ActiveUp.WebControls.Node n in nodes.NodesList) { if (n.ParentKey == "0") { ActiveUp.WebControls.TreeNode node = this.AddNode(n.Key, n.Label, n.Link, n.Target, n.Expanded, n.Icon); //this.Controls.Add(node); } else { ActiveUp.WebControls.TreeNode node = this.FindNode(n.ParentKey).AddNode(n.Key, n.Label, n.Link, n.Target, n.Expanded, n.Icon); //this.Controls.Add(node); } } } }
private System.Windows.Forms.TreeNode AddNodeTreeWindows(System.Web.UI.ControlCollection parentCollection, TreeNode Parent) { System.Windows.Forms.TreeNode ret = null; foreach (object control in parentCollection) { ActiveUp.WebControls.TreeNode child = control as ActiveUp.WebControls.TreeNode; if (child != null) { System.Windows.Forms.TreeNode newNode = new System.Windows.Forms.TreeNode(child.Text); if (child.Expanded == true) { newNode.Expand(); } NodeDesign nodeList = null; if (Parent == null) { _tvTree.Nodes.Add(newNode); nodeList = new NodeDesign(child.Key, "0", child.Text, child.Link); } else { System.Windows.Forms.TreeNode parentNode = GetNode(Parent.Key, _tvTree.Nodes, TypeSearch.searchID); if (parentNode != null) { parentNode.Nodes.Add(newNode); } nodeList = new NodeDesign(child.Key, Parent.Key, child.Text, child.Link); } nodeList.Target = child.Target; nodeList.Expanded = child.Expanded; nodeList.Selected = child.Selected; nodeList.Icon = child.Icon; nodeList.NodeStyle = child.NodeStyle; if (child.Selected == true) { newNode.Checked = true; } newNode.Tag = nodeList; if (child.Nodes.Count > 0) { ret = AddNodeTreeWindows(child.Nodes, child); } if (ret != null) { break; } } } return(ret); }