王朝网络
分享
 
 
 

创建可编辑的xml文档(之五)执行中的treeview 控件

王朝other·作者佚名  2006-01-09
宽屏版  字体: |||超大  

执行中的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

图二 显示了一个目录管理员的窗体, 图三显示了一个详细的最终目录

[url=http://dev.csdn.net/javascript:showSupportItem(][url=file:///E:/学习资料/发表文章/翻译文章/Create%20Editable%20XML%20Documents%20Using%20XPath%20and%20the%20TreeView%20Contro/Create%20Editable%20XML%20Documents%20Using%20XPath%20and%20the%20TreeView%20Control5.files/7456.jpg]

Figure 2. The Catalog Administrator Form: This figure shows the hierarchical TreeView and the details for an item in the catalog administrator form.

[url=http://dev.csdn.net/javascript:showSupportItem(][url=file:///E:/学习资料/发表文章/翻译文章/Create%20Editable%20XML%20Documents%20Using%20XPath%20and%20the%20TreeView%20Contro/Create%20Editable%20XML%20Documents%20Using%20XPath%20and%20the%20TreeView%20Control5.files/7452.jpg]

Figure 3. Final Catalog. The figure shows a detail view of the final catalog.

代码的其他部分处理产品列表的可编辑性,还有更新xml文档。因此当你关闭应用程序时,代码保存所有的修改到文档中。希望这些能够对你的项目有一些好的启发,或者丰富你的组件或者接口的开发。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有