[英]How to add listbox items to settings?
How to add all items from listbox to settings? 如何将列表框中的所有项目添加到设置中? I tried by arraylist but I had error:
我试过arraylist但我有错误:
Object reference not set to an instance of an object.
你调用的对象是空的。
I have no idea how to do this. 我不知道该怎么做。 Settings:
设置:
Name - listboxItems, Type - System.Collections.ArrayList, Scope - Application
名称 - listboxItems,类型 - System.Collections.ArrayList,范围 - 应用程序
private void button9_Click(object sender, EventArgs e)
{
//Save listBox Items
foreach (object item in listBox1.Items)
{
Properties.Settings.Default.listboxItems.Add(item);
}
Properties.Settings.Default.Save();
}
Maybe the listboxItems
entry in the Settings is null. 也许Settings中的
listboxItems
条目为null。 Try: 尝试:
var newList = new ArrayList();
foreach (object item in listBox1.Items)
{
newList.Add(item);
}
Properties.Settings.Default.listboxItems = newList
Properties.Settings.Default.Save();
If you want something typed in your settings (ie string[]
, take a look at this answer . 如果你想在你的设置中输入一些内容(即
string[]
,请看一下这个答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.