So I have this Treeview to which I manually add some items.
Parent nodes can be added without problems, but when I want to add a child node to a parent node that I search by key, it fails for some reason.
This is the code:
tvConstantGroups.Nodes.Add("Boekhouding")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("Exact") 'These 2 lines fail
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("BoB")
The error message that I am getting is that the node "Boekhouding" does not exist (NULL / Nothing)
tvConstantGroups.Nodes.Add("Boekhouding", "Boekhouding")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("Exact", "Exact")
tvConstantGroups.Nodes("Boekhouding").Nodes.Add("BoB", "Exact")
The first parameter of Nodes.Add is Text Not the Name of Node
Related
I'm using dijit.Tree, I need to set a node selected by default (after the data loaded) ? I have tried to search it in dojo documentation, but I didn't find it.
You can select a tree node programmatically by setting the tree's 'path' property. A path is an array of string item id’s, starting with the root node and going down to the leaf node which you want selected.
example:
tree.set('path', ['parent', 'child', 'grandchild'])
In this example grandchild is the node you want selected.
Documentation and examples for this can be found on the Dojo website here
Problem:
In the screenshot below, I have a node 300-9885-00X along with its TreeNodeCollection (in the red square). A little bit lower, we find the 300-9885-00X again, I want to insert the TreeNodeCollection that we found earlier, into that node ...
Background Information
I have a recursive program that goes through AutoCAD / SolidEdge assemblies. It opens the documents and prints the assemblies, and their children, and so on (recursively) ...
Green color means it is printed
Orange means it has already been printed before, so we don't need to print it again...
Question:
How do we insert an existing TreeNodeCollection into a TreeNode?
Knowing:
The location of the TreeNodeCollection
The location of the node in which I want to insert the collection into
The following variable TreeNodes contains my collection. Must I loop through the collection in order to add its text?
You can't add a TreeNodeCollection to a Node. You must loop through the TreeNodeCollection and add the nodes individually like so:
For j As Integer = 0 To TreeNodes.Count - 1
n.Nodes.Add(TreeNodes(j).Clone())
Next
Notice I used .Clone(). This is due to the insertion of an already existing node. You can't do that, you must either delete the existing one or clone it. In my case, I had to clone it.
// Get the '_NodesCollection' from the '_parentNode' TreeNode.
TreeNodeCollection _Nodes = _parentNode.FirstNode.Nodes;
// Create an array of 'TreeNodes'.
TreeNode[] Nodes = new TreeNode[_Nodes.Count];
// Copy the tree nodes to the 'Nodes' array.
_Nodes.CopyTo(Nodes, 0);
// Remove the First Node & Children from the ParentNode.
_parentNode.Nodes.Remove(_parentNode.FirstNode);
// Remove all the tree nodes from the '_parentNode' TreeView.
_parentNode.Nodes.Clear();
// Add the 'Nodes' Array to the '_parentNode' ParentNode.
_parentNode.Nodes.AddRange(Nodes);
// Add the Child Nodes to the TreeView Control
TvMap.Nodes.Add(_parentNode);
Whenever I add a new item (root or child) to a treeview, this is appended to the list (to the bottom of the whole tree).
Is there a way so I can always insert the new items, even for a child node, to the very top of the list or maybe set the order for the inserted items?
P.S. I know how to find the top root, but then I don't know what to do.
Instead of Add, try using Insert:
If TreeView1.Nodes.Count > 0 Then
TreeView1.Nodes(0).Nodes.Insert(0, "First Child Node")
End If
or for the root node:
TreeView1.Nodes.Insert(0, "First Root Node")
I have a tree panel whose nodes are loaded dynamically from the server. When the user expands a node, it will load the children for that node from the server and add them to that node. This part is working.
When the user collapses a node, I'd like to remove all the children from that node and "reset" the node so that it can be exanded again.
So far, I have the following in the collapse event handler:
function(node){
node.removeAll(); // remove all child nodes
// this causes the expand arrow to disappear
node.expandable = true;
// ... now what?
}
How do I "reset" the node (the "... now what?") so that the view knows to add the expand arrow back again?
Essentially I'd like the process of collapsing and then re-expanding a node to reload all of the children under that node.
The solution is to set the loaded field to false. The "expanded" attribute does not need to be changed.
The final solution is:
function(node){
node.removeAll(); // remove all child nodes
node.set('loaded', false); // tell node it can be expanded again
}
I get an XML file From a web service. Now I want to get one of those elements out of the file.
I think I should go use XPath - any good starter reference?
I've just been recovering my XPath skills- this Xslt and XPath Quick Reference sheet is quite a useful reference - it doesn't go into depth but it does list what is available and what you might want to search for more information on.
The w3schools tutorial linked previously isn't that great - it takes a long time to not cover a lot of ground - but it is still worth reading.
Not VB specific, but try this: http://www.w3schools.com/xsl/xpath_intro.asp
One way would be to only extract the needed informations with an xslt file into a new xml and use this new xml as data basis for further processing
If I need to do some XPath, I just tweak one of these examples.
child::node() selects all the children of the context node, whatever their node type
attribute::name selects the name attribute of the context node
attribute::* selects all the attributes of the context node
descendant::para selects the para element descendants of the context node
ancestor::div selects all div ancestors of the context node
ancestor-or-self::div selects the div ancestors of the context node and, if the context node is a div element, the context node as well
descendant-or-self::para selects the para element descendants of the context node and, if the context node is a para element, the context node as well
self::para selects the context node if it is a para element, and otherwise selects nothing
child::chapter/descendant::para selects the para element descendants of the chapter element children of the context node
child::*/child::para selects all para grandchildren of the context node
/ selects the document root (which is always the parent of the document element)
/descendant::para selects all the para elements in the same document as the context node
/descendant::olist/child::item selects all the item elements that have an olist parent and that are in the same document as the context node
child::para[position()=1] selects the first para child of the context node
child::para[position()=last()] selects the last para child of the context node
child::para[position()=last()-1] selects the last but one para child of the context node
child::para[position()>1] selects all the para children of the context node other than the first para child of the context node
following-sibling::chapter[position()=1] selects the next chapter sibling of the context node
preceding-sibling::chapter[position()=1] selects the previous chapter sibling of the context node
/descendant::figure[position()=42] selects the forty-second figure element in the document
/child::doc/child::chapter[position()=5]/child::section[position()=2] selects the second section of the fifth chapter of the doc document element
child::para[attribute::type="warning"] selects all para children of the context node that have a type attribute with value warning
child::para[attribute::type='warning'][position()=5] selects the fifth para child of the context node that has a type attribute with value warning
child::para[position()=5][attribute::type="warning"] selects the fifth para child of the context node if that child has a type attribute with value warning
child::chapter[child::title='Introduction'] selects the chapter children of the context node that have one or more title children with string-value equal to Introduction
child::chapter[child::title] selects the chapter children of the context node that have one or more title children
child::*[self::chapter or self::appendix] selects the chapter and appendix children of the context node
child::*[self::chapter or self::appendix][position()=last()] selects the last chapter or appendix child of the context node
An in depth documentation can be found here. Also these example are taken from there.