Create an editable XML document (v) the TreeView control in execution

Source: Internet
Author: User
Tags filter bool contains execution final version
treeview|xml| Create | control | execute

Execute the TreeView control in order to be more perfect, listing 4 contains the final Treevie controls for vb.net version, or C # versions two editions. To make it easier to use, I redefined the structure and code.  It also adds KeyDown control to support some of the default shortcuts, such as: Control-n (New), F2 (edit), and Del (delete). There seems to be no need to attach any events, so the final API contains a method and eight attributes, which they listed in table 1, most of them are simple flags, or the default switches, I added them in order to allow you to choose to use to enhance your application's editable feature table 1:xmltreeview The properties and methods of the control, you can use them in your application

Attribute Type Parameter Description
Xmldroptarget Get System.Xml.XmlNode The XML node corresponding to the currently selected node in the TreeView
Activexmldocument Get System.Xml.XmlDocument The XML document bound to the TreeView. This is updates as the tree changes
Xpathfilter get; Set String The XPath filter used to identify the element or attribute whose value is used to display the folder ' s name. A folder constitutes the "tree view" s smallest navigable unit
Xmlinsertionnode get; Set System.Xml.XmlNode The template for a new folder. The TreeView caches this, and clones it as a new folder is required.
Dragdropactive get; Set bool Flag denoting whether a drag/drop operation is currently in progress.
Enableeditnode get; Set bool Flag denoting whether label editing is supported (default YES)
Enabledeletenode get; Set bool Flag denoting whether folder deletion is supported (default YES)
Enableinsertnode get; Set bool Flag denoting whether folder insertion is supported (default YES)
Method : Returns   Parameter   Description  
Load void System.Xml.XmlDocument Loads the specified XML document and uses it to populate the TreeView. Set Xpathfilter prior to calling Load () to define a appropriate view on the underlying data.



Call the Sample project  project that is included with this article, and you can see the TreeView control in action, a simple project that is a cut version of the directory administrator I mentioned earlier, and it is necessary to say that you can implement a drag-and-drop operation with just four lines. Figure three shows the user to create a new collection of folders
[C#]
   // Load the XML document from a file
   xmlDocument = new System.Xml.XmlDataDocument();
   xmlDocument.Load(strXmlDocument);
            
   // After setting the path filter, load the 
   // document into the TreeView
   xmlTreeView1.XPathFilter = "attribute::id";
   xmlTreeView1.Load(xmlDocument);
            
   // Defining XmlInsertionNode allows creation of new 
   // nodes within the TreeView
   System.Xml.XmlDocument insert_fragment = new 
      System.Xml.XmlDocument();
   insert_fragment.LoadXml("<product id='New 
      Item'><description/><ordercode/><price/>
      <image/></product>");
   xmlTreeView1.XmlInsertionNode = 
      insert_fragment.DocumentElement;
   
   [VB]
   ' Load the XML document from a file
   xmlDocument = New System.Xml.XmlDataDocument()
   xmlDocument.Load(strXmlDocument)
   
   ' After setting the path filter, load the 
   ' document into the TreeView
   xmlTreeView1.XPathFilter = "attribute::id"
   xmlTreeView1.Load(xmlDocument)
   
   ' Defining XmlInsertionNode allows creation of new 
   ' nodes within the TreeView
   Dim insert_fragment As New System.Xml.XmlDocument()
   insert_fragment.LoadXml("<product id='New " & _
      "Item'><description/><ordercode/><price/>" & _
      "<image/></product>")
   xmlTreeView1.XmlInsertionNode = 
      insert_fragment.DocumentElement
Figure II shows a form for the directory administrator, and figure three shows a detailed final catalog

Figure 2. The Catalog Administrator form:this figure shows the hierarchical TreeView and the details for a item in the Catalog ADM Inistrator form.
Figure 3. Final Catalog. The figure shows a detail view of the final catalog.

Other parts of the code handle the editing of the product list, as well as the updating of the XML document. So when you close the application, the code saves all the changes to the document. Hopefully this will have some good inspiration for your project, or enrich your component or interface development.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.