如何获得在Settings.Default C#中的列表框项目 [英] How to get items in listbox in to Settings.Default C#

查看:227
本文介绍了如何获得在Settings.Default C#中的列表框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去保存在Settings.Default列表框中的项目,但它不会工作,这是我迄今。

  test.Properties.Settings.Default.list = listBox1.Items; 


解决方案

你试过用的ArrayList

  test.Properties.Settings.Default.list =新的ArrayList(listBox1.Items) ; 
test.Properties.Settings.Default.Save();



然后,你可以加载列表后面,像这样:

  listBox1.Items.AddRange(test.Properties.Settings.Default.list.ToArray()); 



我也假设,在你的列表中的项目是可序列化(无论是实施 ISerializable的或有 SerializableAttribute )。


Im trying to save the items in the listbox in Settings.Default but it will not work, this is what i have so far.

test.Properties.Settings.Default.list = listBox1.Items;

解决方案

Have you tried with an ArrayList?

test.Properties.Settings.Default.list = new ArrayList(listBox1.Items);
test.Properties.Settings.Default.Save();

Then you could load the list back like so:

listBox1.Items.AddRange(test.Properties.Settings.Default.list.ToArray());

I'm also assuming that the items in your list are serializable (either implement ISerializable or have the SerializableAttribute).

这篇关于如何获得在Settings.Default C#中的列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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