private static void AssertTreeViewsSame(VirtualTreeView.VirtualTreeNodeCollection nodes1, VirtualTreeView.VirtualTreeNodeCollection nodes2)
        {
            if (nodes1.Count != nodes2.Count)
            {
                var info = new StringBuilder();
                for (int i = 0; i < Math.Max(nodes1.Count, nodes2.Count); i++)
                {
                    info.AppendFormat("[{0},{1}]",
                        nodes1.Count > i ? nodes1[i].Text : "",
                        nodes2.Count > i ? nodes2[i].Text : "");
                }

                Assert.AreEqual(nodes1.Count, nodes2.Count, "The number of nodes is different between the 2 NodeCollections: " + info);
            }

            for (int i = 0; i < nodes1.Count; i++)
            {
                Assert.AreEqual(nodes1[i].Text, nodes2[i].Text, "The text is different between the nodes.");

                if (nodes1[i].Tag == null)
                {
                    Assert.IsNull(nodes2[i].Tag, "The tags are different between the nodes.");
                }
                else
                {
                    Assert.AreEqual(nodes1[i].Tag.ToString(), nodes2[i].Tag.ToString(), "The tags are different between the nodes.");
                }

                Assert.AreEqual(nodes1[i].ImageIndex, nodes2[i].ImageIndex, "The image indexes are different between the nodes for " + nodes1[i].Text);

                AssertTreeViewsSame(nodes1[i].Nodes, nodes2[i].Nodes);
            }
        }
Example #2
0
        public void Setup()
        {
            _vtv = new VirtualTreeView();
            _tv = _vtv;

            // ensure handle is created. Some tests fail if you don't do this.
            IntPtr h = _vtv.Handle;
        }
Example #3
0
		private void SaveNodes(VirtualTreeView.VirtualTreeNodeCollection nodesCollection, XmlTextWriter textWriter)
		{
			for(int i = 0; i < nodesCollection.Count; i++)
			{
				VirtualTreeNode node = nodesCollection[i];
				textWriter.WriteStartElement(XmlNodeTag);
				textWriter.WriteAttributeString(XmlNodeTextAtt, node.Text);
                textWriter.WriteAttributeString(XmlNodeImageIndexAtt, ((Icons)(node.ImageIndex)).ToString());
                if (node.Tag != null) 
					textWriter.WriteAttributeString(XmlNodeTagAtt, node.Tag.ToString());
				
				// add other node properties to serialize here
				
				if (node.Nodes.Count > 0)
				{
					
					SaveNodes(node.Nodes, textWriter);
					    
				} 				
				textWriter.WriteEndElement();
			}
		}		
Example #4
0
		public string SerializeTreeView(VirtualTreeView treeView) 
		{
            Util.ThrowIfParameterNull(treeView, "treeView");

            StringWriter sw = new StringWriter();

			XmlTextWriter textWriter = new XmlTextWriter(sw);
			// writing the xml declaration tag
			textWriter.WriteStartDocument();
			//textWriter.WriteRaw("\r\n");
			// writing the main tag that encloses all node tags
			textWriter.WriteStartElement("VirtualTreeView");
			
			// save the nodes, recursive method
			SaveNodes(treeView.Nodes, textWriter);
			
			textWriter.WriteEndElement();
					
			textWriter.Close();

            return sw.ToString();
		}
 public VirtualTreeSelectedNodeCollection(VirtualTreeView parent)
 {
     Util.ThrowIfParameterNull(parent, "parent");
     _parent = parent;
 }
Example #6
0
		public void DeserializeTreeView(VirtualTreeView treeView, string fileName)
		{
            Util.ThrowIfParameterNull(treeView, "treeView");
            Util.ThrowIfStringParameterNullOrEmpty(fileName, "fileName");

			XmlTextReader reader = null;
			try
			{
                // disabling re-drawing of treeview till all nodes are added
				treeView.BeginUpdate();				
				reader =
					new XmlTextReader(fileName);

				VirtualTreeNode parentNode = null;
				
				while (reader.Read())
				{
					if (reader.NodeType == XmlNodeType.Element)
					{						
						if (reader.Name == XmlNodeTag)
						{
							VirtualTreeNode newNode = new VirtualTreeNode("");
							bool isEmptyElement = reader.IsEmptyElement;

                            // loading node attributes
							int attributeCount = reader.AttributeCount;
							if (attributeCount > 0)
							{
								for (int i = 0; i < attributeCount; i++)
								{
									reader.MoveToAttribute(i);
									
									SetAttributeValue(newNode, reader.Name, reader.Value);
								}								
							}

                            // add new node to Parent Node or VirtualTreeView
                            if(parentNode != null)
                                parentNode.Nodes.Add(newNode);
                            else
                                treeView.Nodes.Add(newNode);

                            // making current node 'ParentNode' if its not empty
							if (!isEmptyElement)
							{
                                parentNode = newNode;
							}
														
						}						                    
					}
                    // moving up to in VirtualTreeView if end tag is encountered
					else if (reader.NodeType == XmlNodeType.EndElement)
					{
						if (reader.Name == XmlNodeTag)
						{
							parentNode = parentNode.Parent;
						}
					}
					else if (reader.NodeType == XmlNodeType.XmlDeclaration)
					{ //Ignore Xml Declaration                    
					}
					else if (reader.NodeType == XmlNodeType.None)
					{
						return;
					}
					else if (reader.NodeType == XmlNodeType.Text)
					{
						parentNode.Nodes.Add(new VirtualTreeNode(reader.Value));
					}

				}
			}
			finally
			{
                // enabling redrawing of treeview after all nodes are added
				treeView.EndUpdate();      
                reader.Close();	
			}
		}
 private VirtualTreeView DeserializeTreeView(string testResource)
 {
     VirtualTreeView treeView = new VirtualTreeView();
     new TreeViewSerializer().DeserializeTreeView(treeView, GetTestResource(testResource));
     return treeView;
 }