Running Treeview Control
For perfection, list 4 contains the final treevie control of VB. NET version and or C # version. To make it easier to use, I have redefined the structure and code. The keydown control is added to support some default shortcut keys, such as control-N (new), F2 (edit), and del (delete ).
It seems that there is no need to attach any event, so the final API contains a method and eight attributes. They are listed in Table 1. Most of them are simple signs or default switches, I added them so that you can choose to use them to enhance the Editable features of your application.
Table 1: attributes and methods of the xmltreeview 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 updates as the tree changes
Xpathfilter
Get; Set
String
The XPath filter used to identify the element or attribute whose value will be 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 when 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 is yes)
EnableDeleteNode
Get; Set
Bool
Flag denoting whether folder deletion is supported (default is yes)
EnableInsertNode
Get; Set
Bool
Flag denoting whether folder insertion is supported (default is 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 an appropriate view on the underlying data.
Call the sample project that is attached to this article. You can see the treeview control in progress. This simple project is a cut version of the directory administrator I mentioned earlier. It is also necessary to say that, you only need four lines to implement a drag-and-drop operation. Figure 3 shows how to create a folder set.
[C #]
// Load the XML document from a file
XmlDocument = new System. Xml. XmlDataDocument ();
XmlDocument. Load (strXmlDocument );
// After setting the path filter, load
// 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
'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 2 shows a directory administrator form, and Figure 3 shows a detailed final directory
Figure 2. The Catalog Administrator Form: This figure shows the hierarchical TreeView and the details for an item in the catalog administrator form.
Figure 3. Final Catalog. The figure shows a detail view of the final catalog.
Other parts of the Code process the Editable product list and update the xml document. Therefore, when you close the application, save all the modifications to the Code in the document. I hope these will give you some good inspiration for your project, or enrich the development of your components or interfaces.