[英]How to get items in listbox in to Settings.Default C#
我试图在Settings.Default中保存列表框中的项目,但它不起作用,这是我到目前为止。
test.Properties.Settings.Default.list = listBox1.Items;
Changes to properties will not persist if you don't call Save()
afterwards. 如果之后不调用
Save()
,则属性的更改将不会保留。
test.Properties.Settings.Default.list = listBox1.Items;
test.Properties.Settings.Default.Save();
Have you tried with an ArrayList
? 你试过过
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
). 我还假设列表中的项目是可序列化的(实现
ISerializable
或具有SerializableAttribute
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.