Treeview对象:存储和检索 [英] Treeview object: storage and retrieval

查看:119
本文介绍了Treeview对象:存储和检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿!如何将树视图节点的文本属性存储在文件中,并在以后以与创建时相同的树视图格式检索它们?

Hey! How can I store a treeview nodes text properties in a file and retrieve them back later in the same treeview format as it was created? Is it possible to save it in linear format in a text file and then retrive it somehow?

推荐答案

尝试在这里查看: ^ ]
Try looking here: Loading and Saving a TreeView control to an XML file using XmlTextWriter and XmlTextReader[^]


最好的方法是基于UI与应用程序其他部分的隔离.您不想直接声明和恢复状态.您需要与UI无关的单独的数据模型,但数据模型应公开给UI.这样,您将创建松散耦合方法:
http://en.wikipedia.org/wiki/Loose_coupling [串行化:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework [ http://msdn.microsoft.com/en-us/library/ms233843.aspx [ ^ ].

好的序列化代码应该能够存储/恢复任意对象图,并且对数据模型非侵入性.这意味着应该以与序列化机制无关的方式来开发数据模型.

完美的工具是数据合同.请参阅:
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

在我倡导这种方法的地方,也请参阅我过去的答案.您无需更改数据中的任何内容,只需添加一些.NET 属性.请参阅:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [ http://en.wikipedia.org/wiki/Finite-state_machine [ http://en.wikipedia.org/wiki/State_diagram [
The best approach is based on the isolation of the UI from the other parts of the application. You don''t want to state and restore the state directly. You need to have a separate data model agnostic to your UI, but the data model should be exposed to UI. This way, you will create a loose-coupling approach:
http://en.wikipedia.org/wiki/Loose_coupling[^].

You UI should be able to populate from the model, modify the model or store modified data to the model. As to the persistence of the state, you should have persistence based on the model, not the UI.

The persistent mechanism should be agnostic of the particular data schema (metadata), to be re-usable and reliable. To get such thing, you need to learn about serialization:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework[^],
http://msdn.microsoft.com/en-us/library/ms233843.aspx[^].

The good serialization code should be able to store/restore any arbitrary object graph and be non-intrusive to the data model. It means that the data model should be developed in a way agnostic to serialization mechanism.

The perfect tool for such thing is Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please also see my past answers where I advocate this approach. You don''t have to change anything in your data, you only add some .NET attributes. Please see:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

See also:
http://en.wikipedia.org/wiki/Finite-state_machine[^],
http://en.wikipedia.org/wiki/State_diagram[^].

—SA


这篇关于Treeview对象:存储和检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆