[英]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.