いつもお世話になっております。
現在、プログラム内で固定数値や文字列を使う際、app.configに値を保存しておいて
必要な時に呼び出す方法で作っています。
しかしこれだと、固定数値や文字列を編集したいときに手動で編集する必要があります。
本来こういった固定数値や文字列をプログラム側から編集はしないのが一般的ですが、ユーザがある程度設定を変更できるインターフェースを作りたいときに不便です。
app.configに保存するのではなく、別の場所(例えばテキストファイルとか)に保存・取得・編集ができる方法はありませんでしょうか?
追記:app.configを利用して同じものができました。
こんな感じのものをapp.configを使わずに作りたいと思っています。
プログラムは以下の通りです。
public partial class frmEditConfig : Form
{
public frmEditConfig()
{
InitializeComponent();
}
private void frmEditConfig_Load(object sender, EventArgs e) { loadDGV(); } private void loadDGV() { dataGridView1.Rows.Clear(); for (int i = 0; i < ConfigurationManager.AppSettings.Count; i++) { dataGridView1.Rows.Add(); dataGridView1[0, i].Value = ConfigurationManager.AppSettings.Keys[i]; dataGridView1[1, i].Value = ConfigurationManager.AppSettings[i]; } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { textBox1.Text = dataGridView1[0, e.RowIndex].Value.ToString(); textBox2.Text = dataGridView1[1, e.RowIndex].Value.ToString(); } private void button1_Click(object sender, EventArgs e) { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings[textBox1.Text].Value = textBox2.Text; config.Save(ConfigurationSaveMode.Full); loadDGV(); } }
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/04/02 08:30
退会済みユーザー
2018/04/03 00:24