创建可编辑的xml文档(之五)执行中的treeview 控件
2005-12-29 13:21
363 查看
执行中的treeview 控件
为了更完美,列表4包含了VB.NET version, or C# version 两个版本的最终treevie 控件。为了更容易使用,我重新定义了结构和代码。同时增加了KeyDown 控制来支持一些默认的快捷键例如:Control-N (新建), F2 (编辑), 和DEL (删除).
这里好象不必附加任何事件,因此最终的api 包含一个方法和八个属性,他们在表1中列出来了,他们大多数都是简单的标志,或者默认的开关,我增加他们时为了让你可以选择使用来增强你的应用程序的可编辑特征
表1:xmltreeview 控件的属性和方法,你可以将它们用到你的应用程序中
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.
调用本文章附带的sample project 工程,你可以看到执行中的treeview 控件,这个简单工程是我前面提到的目录管理员中一个剪切版本,还有必要说一下,只需要四行就可以实现一个拖放操作,图三显示让用户创建新的文件夹集合
[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 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.
代码的其他部分处理产品列表的可编辑性,还有更新xml文档。因此当你关闭应用程序时,代码保存所有的修改到文档中。希望这些能够对你的项目有一些好的启发,或者丰富你的组件或者接口的开发。
为了更完美,列表4包含了VB.NET version, or C# version 两个版本的最终treevie 控件。为了更容易使用,我重新定义了结构和代码。同时增加了KeyDown 控制来支持一些默认的快捷键例如:Control-N (新建), F2 (编辑), 和DEL (删除).
这里好象不必附加任何事件,因此最终的api 包含一个方法和八个属性,他们在表1中列出来了,他们大多数都是简单的标志,或者默认的开关,我增加他们时为了让你可以选择使用来增强你的应用程序的可编辑特征
表1:xmltreeview 控件的属性和方法,你可以将它们用到你的应用程序中
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.
调用本文章附带的sample project 工程,你可以看到执行中的treeview 控件,这个简单工程是我前面提到的目录管理员中一个剪切版本,还有必要说一下,只需要四行就可以实现一个拖放操作,图三显示让用户创建新的文件夹集合
[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 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.
代码的其他部分处理产品列表的可编辑性,还有更新xml文档。因此当你关闭应用程序时,代码保存所有的修改到文档中。希望这些能够对你的项目有一些好的启发,或者丰富你的组件或者接口的开发。
相关文章推荐
- 创建可编辑的xml文档(之五)执行中的treeview 控件
- 创建可编辑的xml文档(之一)绑定xml文档到treeview 控件
- 创建可编辑的xml文档(之三)执行拖放操作
- 创建可编辑的xml文档(之二) 过滤xml 数据
- 创建可编辑的xml文档(之四) 删除、改名、插入操作
- 创建、编辑、删除XML文档及文档的内容
- 创建可编辑的xml文档(之二) 过滤xml 数据
- 创建可编辑的xml文档(之四) 删除、改名、插入操作
- NSIS ---使用nsDialogs创建自定义页面,并获取输入到控件中的内容保存到一个XML文档中
- winform实现 绑定xml文档到treeview 控件
- winform实现 绑定xml文档到treeview 控件
- 创建可编辑的xml文档(之四) 删除、改名、插入操作 YAOTIEBING [翻译]
- 使用JDom来创建XML文档实例,需要引入jdom.jar包
- 在线编辑office文档控件
- Java创建XML文档的SAX方式
- JDOM入门实例:读取与创建xml文档
- DeltaOffice 在线编辑控件说明文档
- 自己开发基于Web的在线编辑文档控件,可以在线编辑任意文档
- JDOM操作XML文档高级篇XML验证,创建带名字空间的xml, xml文档的修改
- [ZZ]如何在Web页面上直接打开、编辑、创建Office文档