[英]Edit contents of Setting File (settings.settings) in DataGridView
我正在尝试在DataGridView中显示setting.setting文件的内容。
通过使用BindingSource如下绑定数据,我已经成功做到了
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataSource = Properties.user.Default.Properties;
settingsDataGridView.DataSource = bindingSource1;
使用此代码,将使用以下默认值填充我的DataGridView
Setting Name
是只读的。
Settings Value
是可编辑的。
我在表单上提供了一个Save
按钮,该按钮在OnClick
事件中具有以下代码
Properties.user.Default.Save();
想法是让用户使用简单的界面来更改设置。
不幸的是,这并不能解决问题。 Save
按钮不会更改settings.settings
文件中的值,并且修改的数据在应用程序运行之间不会保留。
我的问题:
大家的帮助真的很感激。
如果使用PropertyGrid也可以:
propertyGrid1.SelectedObject = Properties.Settings.Default; propertyGrid1.BrowsableAttributes = new AttributeCollection(new UserScopedSettingAttribute());
propertyGrid1.SelectedObject = Properties.Settings.Default; propertyGrid1.BrowsableAttributes = new AttributeCollection(new UserScopedSettingAttribute());
Properties.Settings.Default.Save();
代码应类似于以下内容:
using System;
using System.ComponentModel;
using System.Configuration;
using System.Windows.Forms;
namespace YourAppNamespace
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = Properties.Settings.Default;
propertyGrid1.BrowsableAttributes = new AttributeCollection(new UserScopedSettingAttribute());
}
private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
{
Properties.Settings.Default.Save();
}
}
}
如果设置文件包含范围为“用户”的设置,则应将其显示并保存(如果更改)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.