我试图在Settings.Default中保存列表框中的项目,但它不起作用,这是我到目前为止。
test.Properties.Settings.Default.list = listBox1.Items;
Changes to properties will not persist if you don't call Save()
afterwards.
test.Properties.Settings.Default.list = listBox1.Items;
test.Properties.Settings.Default.Save();
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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.