質問編集履歴
1
画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,93 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
app.configに保存するのではなく、別の場所(例えばテキストファイルとか)に保存・取得・編集ができる方法はありませんでしょうか?
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
追記:app.configを利用して同じものができました。
|
22
|
+
|
23
|
+
こんな感じのものをapp.configを使わずに作りたいと思っています。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
![イメージ説明](dc561c22e833e59c741d0516dc1b7511.png)
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
プログラムは以下の通りです。
|
32
|
+
|
33
|
+
public partial class frmEditConfig : Form
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
public frmEditConfig()
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
InitializeComponent();
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
private void frmEditConfig_Load(object sender, EventArgs e)
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
loadDGV();
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
private void loadDGV()
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
dataGridView1.Rows.Clear();
|
62
|
+
|
63
|
+
for (int i = 0; i < ConfigurationManager.AppSettings.Count; i++)
|
64
|
+
|
65
|
+
{
|
66
|
+
|
67
|
+
dataGridView1.Rows.Add();
|
68
|
+
|
69
|
+
dataGridView1[0, i].Value = ConfigurationManager.AppSettings.Keys[i];
|
70
|
+
|
71
|
+
dataGridView1[1, i].Value = ConfigurationManager.AppSettings[i];
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
textBox1.Text = dataGridView1[0, e.RowIndex].Value.ToString();
|
84
|
+
|
85
|
+
textBox2.Text = dataGridView1[1, e.RowIndex].Value.ToString();
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
private void button1_Click(object sender, EventArgs e)
|
92
|
+
|
93
|
+
{
|
94
|
+
|
95
|
+
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
config.AppSettings.Settings[textBox1.Text].Value = textBox2.Text;
|
100
|
+
|
101
|
+
config.Save(ConfigurationSaveMode.Full);
|
102
|
+
|
103
|
+
loadDGV();
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|