[英]How do I save multiple user settings in runtime in C#
I am trying to make my app stay the way I left it after closing the app.我试图让我的应用程序在关闭应用程序后保持原样。 Therefore I want to save set of items from ListView to the settings and I can't figure out how to do that.
因此,我想将 ListView 中的一组项目保存到设置中,但我不知道该怎么做。 I've found some solutions but I believe they are outdated as they don't seem to work.
我找到了一些解决方案,但我相信它们已经过时,因为它们似乎不起作用。
Image shows set of items in ListView which I want to save so they appear there after restarting the app:图像显示了我要保存的 ListView 中的一组项目,以便它们在重新启动应用程序后出现:
This is where I want them to appear:这是我希望它们出现的地方:
And this is part of code that I've tried out so far这是我迄今为止尝试过的代码的一部分
private void btn_SaveConfig_Click(object sender, EventArgs e)
{
int i = 0;
Settings.Default["IP"] = tBox_discoverServerFrom.Text;
Settings.Default["DiscoveredServers"] = cBox_discoveredServers.Text;
foreach (var item in lV_groups.Items)
{
var property = new System.Configuration.SettingsProperty("Group"+i);
property.PropertyType = typeof(string);
property.Name = "Group " + i;
Settings.Default.Properties.Add(property);
Settings.Default.Save();
i++;
}
}
I do not think using the Settings API is a great idea if you want to save any significant amount of data.如果您想保存大量数据,我认为使用设置 API 不是一个好主意。
I would recommend the following我会推荐以下
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.