Perform deletion, rename, insert operation
It has been the most difficult part of the drag and drop operation, but it should also provide some better basic editing functions for integrity considerations. The following only use four lines of code to implement the deletion:
[C #]
String Xpath_Query =
BuildXPathQuery (this.selectedNode);
System.xml.xmlNode Node =
XML_Document.documentelement.selectsinglenode (
XPath_Query);
Node.ParentNode.RemoveChild (Node);
SelectedNode.Remove ();
[Vb]
DIM XPATH_QUERY AS STRING = _
BuildxpathQuery (me.selectednode)
Dim node as system.xml.xmlnode = _
XML_Document.documentelement.selectsinglenode (_
XPath_Query)
node.parentnode.removeChild (Node)
SELECTEDNODE.REMOVE ()
The renaming operation requires more consideration, you can call BuildXPathQuery to find that folder is being edited, how is it determined which property, how to determine the elements or child elements of the return structure that is displayed accordingly? This is a misleading problem, the XPath Filte function has been defined, you only need to apply a current conversion:
[C #]
Private void XmltreeView_AFTERLABELEDIT (Object Sender,
System.windows.Forms.NodeLabelediteventArgs E)
{
String Xpath_Query = BuildXPathQuery (E.NODE);
System.xml.xmlNode Node =
XML_Document.documentelement.selectsinglenode (
XPath_Query);
System.xml.xmlnode label =
node.selectsinglenode (xpath_filter);
Label.Value = E.Label;
}
[Vb]
Private sub XmltreeView_AFTERLABELEDIT (_
Byval sender as object, _
ByVal e as
System.windows.forms.nodelabelediteventargs_
Handles mybase.AFTERLABELEDIT
DIM XPATH_QUERY AS STRING = BuildxPathQuery (E.NODE)
Dim node as system.xml.xmlnode = _
XML_Document.documentelement.selectsinglenode (_
XPath_Query)
Dim label as system.xml.xmlnode =
Node.selectsinglenode (xpath_filter)
Label.Value = E.Label
End Sub
The last challenge is how to create a new folder in accordance with the needs. Query Filter allows the user to operate an XML document with a set of folders instead of an XML element. This is helpful to move around those folders, and it can also tell where to insert a folder, but it can't tell you what this folder should contain, you should guess all the folders in the document. Whether it contains the same structure or content. But our goal is to create an XML method that does not require any predetermined display. Therefore, I chose to entrust these to the application control. For example, client code can be written below: [C #]
System.xml.xmldocument INSERT_FRAGMENT =
New system.xml.xmldocument ();
INSERT_FRAGMENT.LOADXML
"
// the treeview uses xmlinsertionNode to add
// a new folder to the tree's underlying XML
// Document On Request
XmltreeView1.xmlinsertionNode =
INSERT_FRAGMENT.DOCUMENTELEMENT;
[Vb]
DIM INSERT_FRAGMENT AS New System.xml.xmldocument ()
INSERT_FRAGMENT.LOADXML ("& _)
"
XmltreeView1.xmlinsertionNode = _
INSERT_FRAGMENT.DOCUMENTELEMENT
The TreeView control can cache a copy of a structure, use it as a temporary variable to create a new folder collection. What you have to do is ensuring that the defined folder can be identified by Filter Query, otherwise TreeView will not display it. Because of the documentation for our operation, XML is usually external (External). I need to import into the document before I use it.
[C #]
//First you need to clone the node template, and
// Import it, Because it Originates from a differentrent
// Document
System.xml.xmlnode Copy_Node = new_node.clone ();
System.xml.xmlnode insert_node =
XML_Document.ImportNode (Copy_Node, True);
// Next Locate Which Node Should Be ITS Parent, And
// IT IT
String Xpath_Query =
BuildXPathQuery (this.selectedNode);
System.xml.xmlNode Node =
XML_Document.documentelement.selectsinglenode (
Xpath_Query); node.appendchild (insert_node);
// finally, apply the xpath filter to determine What
// to Display
System.xml.xmlNode Expr =
INSERT_NODE.SELECTSINGLENODE (XPath_Filter);
System.windows.Forms.treenode new_child =
SELECTEDNODE.NODES.ADD (Expr.Value);
PopulaTreeControl (Insert_Node, New_Child.nodes);
// select the node, to force the tree to expand
SELECTEDNODE = New_CHILD;
// and start editing the new folder name
Suppress_label_edit = false;
New_child.beginedit ();
[Vb]
'First you need to clone the node template, And
'Import IT, Because It Originates from A Different
'Document.
DIM COPY_NODE as system.xml.xmlnode = new_node.clone ()
DIM INSERT_NODE as system.xml.xmlnode = _
XML_Document.ImportNode (Copy_Node, True)
'Next Locate Which Node Should Be ITS Parent,
'and IT IT
DIM XPATH_QUERY AS STRING = _
BuildxpathQuery (me.selectednode)
DIM node as system.xml.xmlnode =
XML_Document.documentelement.selectsinglenode (_
XPath_Query)
Node.Appendchild (Insert_Node)
'Finally, Apply the XPath Filter to Determine What
'Should Be
'Displayed
DIM EXPR AS System.xml.xmlnode = _
INSERT_NODE.SELECTSINGLENODE (XPath_Filter)
DIM new_child as system.windows.forms.treenode = _
SELECTEDNODE.NODES.ADD (Expr.Value)
PopulaTreeControl (Insert_Node, New_Child.nodes)
'Select the node, to force the tree to expand
SELECTEDNODE = New_CHILD
'And start editing the new folder name
Suppress_Label_EDit = false
New_child.beginedit ()