質問編集履歴
1
質問追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -147,3 +147,197 @@
|
|
147
147
|
}
|
148
148
|
|
149
149
|
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
### 前提・実現したいこと(追記)
|
156
|
+
|
157
|
+
上記のコードから、DataGridのソース元を配列から2次元Listに変更しました。
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
### 該当のソースコード
|
162
|
+
|
163
|
+
```C#
|
164
|
+
|
165
|
+
public ObservableCollection<DataGrid_Data> Source_DG = new ObservableCollection<DataGrid_Data>();
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public List<List<string>> ItemNames = new List<List<string>>(); //リスト化
|
170
|
+
|
171
|
+
public List<List<string>> ItemCodes = new List<List<string>>(); //リスト化
|
172
|
+
|
173
|
+
public List<List<string>> ItemEnables = new List<List<string>>(); //リスト化
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
public string[] str_ItemNames = { "AAA", "BBB", "CCC", "DDD" };
|
180
|
+
|
181
|
+
public string[] str_ItemCodes = { "aaa", "bbb", "ccc", "ddd" };
|
182
|
+
|
183
|
+
public string[] str_ItemEnables = { "111", "222", "333", "444" };
|
184
|
+
|
185
|
+
public string[] str_Dummys = { "0", "00", "000", "0000" };
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
public int group = 0;
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
public MainWindow()
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
InitializeComponent();
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
Init_ItemList();
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
for (int i = 0; i < str_ItemCodes.Length; i++)
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
Source_DG.Add(new DataGrid_Data(ItemNames[group][i], ItemCodes[group][i], ItemEnables[group][i]) { });
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
dataGrid.ItemsSource = Source_DG;
|
220
|
+
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
public void Init_ItemList()
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
for (int i = 0; i < 4; i++)
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
ItemNames.Add(new List<string>());
|
234
|
+
|
235
|
+
ItemCodes.Add(new List<string>());
|
236
|
+
|
237
|
+
ItemEnables.Add(new List<string>());
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
ItemNames[group].AddRange(str_ItemNames);
|
244
|
+
|
245
|
+
ItemCodes[group].AddRange(str_ItemCodes);
|
246
|
+
|
247
|
+
ItemEnables[group].AddRange(str_ItemEnables);
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
ItemNames[group + 1].AddRange(str_Dummys);
|
252
|
+
|
253
|
+
ItemCodes[group + 1].AddRange(str_Dummys);
|
254
|
+
|
255
|
+
ItemEnables[group + 1].AddRange(str_Dummys);
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
ItemNames[group +2].AddRange(str_ItemNames);
|
260
|
+
|
261
|
+
ItemCodes[group +2].AddRange(str_ItemCodes);
|
262
|
+
|
263
|
+
ItemEnables[group +2].AddRange(str_ItemEnables);
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
public class DataGrid_Data
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
public string Data_Name { get; set; }
|
276
|
+
|
277
|
+
public string Data_Code { get; set; }
|
278
|
+
|
279
|
+
public string Data_Enable { get; set; }
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
public DataGrid_Data(string Name, string Code, string Enable)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
Data_Name = Name;
|
288
|
+
|
289
|
+
Data_Code = Code;
|
290
|
+
|
291
|
+
Data_Enable = Enable;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
private void Button1_Click(object sender, RoutedEventArgs e)
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
group = int.Parse(TextBox.Text);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
Source_DG.Clear();
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
for (int i = 0; i < str_ItemCodes.Length; i++)
|
312
|
+
|
313
|
+
{
|
314
|
+
|
315
|
+
Source_DG.Add(new DataGrid_Data(ItemNames[group][i], ItemCodes[group][i], ItemEnables[group][i]) { });
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
dataGrid.ItemsSource = Source_DG;
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
private void Button2_Click(object sender, RoutedEventArgs e)
|
328
|
+
|
329
|
+
{
|
330
|
+
|
331
|
+
/*
|
332
|
+
|
333
|
+
ItemNames = Source_DG.Select(x => x.Data_Name).ToArray();
|
334
|
+
|
335
|
+
ItemCodes = Source_DG.Select(x => x.Data_Code).ToArray();
|
336
|
+
|
337
|
+
ItemEnables = Source_DG.Select(x => x.Data_Enable).ToArray();
|
338
|
+
|
339
|
+
*/
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
```
|