如何在Windows窗体中保存和加载ListView的内容? [英] How to save and load a ListView's Content in a windows form?

查看:83
本文介绍了如何在Windows窗体中保存和加载ListView的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我有Windows表格申请表。它是一个MP3播放器,它包含一个wmp.dll,一个列表视图和三个按钮,一个按钮向我显示一个OpenFileDialog,我可以在其中选择多首歌曲,当我在Dialog中单击OK时它会显示我选择的歌曲列表视图有两列:标题和位置;



我想要一个按钮来保存ListView的内容,所以当我关闭表格并再次运行时,它会显示我之前保存的播放列表。 br />


首先,我无法弄清楚如何做到这一点。

其次,在搜索谷歌后,我试图保存内容与Xml,TXT,没有一种方法解决了问题。



请帮助我解决这个问题,我正在解决这个问题。



感谢提前!

解决方案

最好不要自己弄乱XML或任何其他文件,但要使用序列化。对你来说最好的序列化方法可能就是使用 Data Contract http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx [ ^ ]。



这样,您可以以任意对象图形式存储任何数据模型,将其保存在文件中,并将其恢复到内存中,就像保存之前一样。因此,您不使用UI或XML,而是处理数据。另请参阅我过去的答案,我提倡这种强有力的方法:

创建属性文件...... [ ^ ],

如何在我的表单应用程序中使用XML文件编写器和阅读器? [ ^ ]。



-SA

Hi everybody!

I have a Windows Form Application. It is a MP3 Player, it consists in a wmp.dll, a listview, and three buttons, one button shows me an OpenFileDialog, in which I can choose multiple songs, when I click OK in the Dialog it shows me the selected songs in the listview which has two columns: Title and Location;

I want a button to save the ListView's content so when I close the form and run it again, it will show me the "playlist" that I saved before.

First of all, I can't figure out how to do that.
Second, after searching on google, I tried to save the content with Xml, TXT, and no one of this methods got the problem solved.

Please help me with this problem, I'm breaking my head to solve it.

THANKS IN ADVANCE!

解决方案

It's better not to mess with XML or any other files by yourself, but to use serialization. Probably the best serialization method for you would be using Data Contract: http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].

This way, you can have any data model in the form of any arbitrary object graphs, save it in the file, and that restore it in memory as it was before saving. So, you work not with UI or XML, but with data. See also my past answers where I advocate this powerful approach:
Creating property files...[^],
How can I utilize XML File streamwriter and reader in my form application?[^].

—SA


这篇关于如何在Windows窗体中保存和加载ListView的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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