質問編集履歴
8
調査結果の記述箇所を試したことの下に移動
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,454 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
### 実現したいこと
|
30
|
+
|
31
|
+
たとえDBが空の状態でデータを読み込んでも(一回目の起動で)
|
32
|
+
|
33
|
+
正しくTest_Listの内容を表示できるようにしたいです。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
### コード
|
38
|
+
|
39
|
+
MainWindow.xaml.cs
|
40
|
+
|
41
|
+
```C#
|
42
|
+
|
43
|
+
using Npgsql;
|
44
|
+
|
45
|
+
using System;
|
46
|
+
|
47
|
+
using System.Collections.Generic;
|
48
|
+
|
49
|
+
using System.Data;
|
50
|
+
|
51
|
+
using System.Linq;
|
52
|
+
|
53
|
+
using System.Text;
|
54
|
+
|
55
|
+
using System.Text.RegularExpressions;
|
56
|
+
|
57
|
+
using System.Windows;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
namespace WpfApp1
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
public partial class MainWindow : Window
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
public DataTable dataTable { get; } = new DataTable();
|
70
|
+
|
71
|
+
public MainWindow()
|
72
|
+
|
73
|
+
{
|
74
|
+
|
75
|
+
using (var conn = new NpgsqlConnection("Server=localhost; Port=5432; Database=postgres;User Id=postgres;Password=postgres;"))
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
conn.Open();
|
80
|
+
|
81
|
+
using (var command = conn.CreateCommand())
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
StringBuilder sb = new StringBuilder();
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
sb.Clear();
|
90
|
+
|
91
|
+
sb.Append("CREATE TABLE IF NOT EXISTS public.tblcat (");
|
92
|
+
|
93
|
+
sb.Append(" num INTEGER NOT NULL");
|
94
|
+
|
95
|
+
sb.Append(" , name VARCHAR(20) NOT NULL");
|
96
|
+
|
97
|
+
sb.Append(" , test VARCHAR(40)");
|
98
|
+
|
99
|
+
sb.Append(" , PRIMARY KEY (num, name)");
|
100
|
+
|
101
|
+
sb.Append(")");
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
command.CommandText = sb.ToString();
|
106
|
+
|
107
|
+
command.ExecuteNonQuery();
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
conn.Close();
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
CreateDataTable();
|
116
|
+
|
117
|
+
InitializeComponent();
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
private void CreateDataTable()
|
124
|
+
|
125
|
+
{
|
126
|
+
|
127
|
+
DataColumnCollection columns = dataTable.Columns;
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
if (!columns.Contains(nameof(CatModel.Num)))
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
DataColumn dataColumn_Num = dataTable.Columns.Add(nameof(CatModel.Num), typeof(int));
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
if (!columns.Contains(nameof(CatModel.Name)))
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
DataColumn dataColumn_Name = dataTable.Columns.Add(nameof(CatModel.Name), typeof(string));
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
using (var context = new PgDbContext())
|
152
|
+
|
153
|
+
{
|
154
|
+
|
155
|
+
var tblCat = context.Cats;
|
156
|
+
|
157
|
+
IQueryable<Cat> result;
|
158
|
+
|
159
|
+
result = from x in tblCat
|
160
|
+
|
161
|
+
select x;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
int columnCount = 0;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
foreach (Cat cat in result.ToList())
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
174
|
+
|
175
|
+
double?[] test_list = numbers.Split(',')
|
176
|
+
|
177
|
+
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
178
|
+
|
179
|
+
.ToArray<double?>();
|
180
|
+
|
181
|
+
columnCount = test_list.Length;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
for (int i = 0; i < columnCount; i++)
|
188
|
+
|
189
|
+
{
|
190
|
+
|
191
|
+
if (!columns.Contains($"Test_{i + 1}"))
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
dataTable.Columns.Add(new DataColumn($"Test_{i + 1}", typeof(int)));
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
} // ここにブレークポイントを貼る
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
foreach (Cat cat in result.ToList())
|
204
|
+
|
205
|
+
{
|
206
|
+
|
207
|
+
var row = dataTable.NewRow();
|
208
|
+
|
209
|
+
row[0] = cat.Num;
|
210
|
+
|
211
|
+
row[1] = cat.Name;
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
216
|
+
|
217
|
+
double?[] test_list = numbers.Split(',')
|
218
|
+
|
219
|
+
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
220
|
+
|
221
|
+
.ToArray<double?>();
|
222
|
+
|
223
|
+
columnCount = test_list.Length;
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
for (int i = 0; i < columnCount; i++)
|
228
|
+
|
229
|
+
{
|
230
|
+
|
231
|
+
row[2 + i] = (test_list[i] == null) ? DBNull.Value : test_list[i];
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
dataTable.Rows.Add(row);
|
236
|
+
|
237
|
+
} // ここにブレークポイントを貼る
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
private void imp_button_Click(object sender, RoutedEventArgs e)
|
246
|
+
|
247
|
+
{
|
248
|
+
|
249
|
+
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
250
|
+
|
251
|
+
using (var context = new PgDbContext())
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
var table = context.Cats;
|
256
|
+
|
257
|
+
foreach (Cat cat in list)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
context.Cats.Add(cat);
|
266
|
+
|
267
|
+
context.SaveChanges();
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
CreateDataTable();
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
MainWindow.xaml
|
288
|
+
|
289
|
+
```XAML
|
290
|
+
|
291
|
+
<Window x:Class="WpfApp1.MainWindow"
|
292
|
+
|
293
|
+
x:Name="mainWindow"
|
294
|
+
|
295
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
296
|
+
|
297
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
298
|
+
|
299
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
300
|
+
|
301
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
302
|
+
|
303
|
+
mc:Ignorable="d"
|
304
|
+
|
305
|
+
Title="List" Height="350" Width="750"
|
306
|
+
|
307
|
+
BorderThickness="1">
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
<Grid Width="700" Height="700">
|
312
|
+
|
313
|
+
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding dataTable, ElementName=mainWindow}"
|
314
|
+
|
315
|
+
HorizontalAlignment="Left" Margin="10,10,10,10"/>
|
316
|
+
|
317
|
+
<Button x:Name="imp_button" Content="Import CSV" HorizontalAlignment="Left" Margin="250,273,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="imp_button_Click"/>
|
318
|
+
|
319
|
+
</Grid>
|
320
|
+
|
321
|
+
</Window>
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
Cat.cs
|
328
|
+
|
329
|
+
```C#
|
330
|
+
|
331
|
+
using System;
|
332
|
+
|
333
|
+
using System.ComponentModel.DataAnnotations;
|
334
|
+
|
335
|
+
using System.ComponentModel.DataAnnotations.Schema;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
namespace WpfApp1
|
340
|
+
|
341
|
+
{
|
342
|
+
|
343
|
+
[Table("tblcat")]
|
344
|
+
|
345
|
+
class Cat
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
[Key]
|
350
|
+
|
351
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
352
|
+
|
353
|
+
[Column("num", Order = 2)]
|
354
|
+
|
355
|
+
public int Num { get; set; }
|
356
|
+
|
357
|
+
[Key]
|
358
|
+
|
359
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
360
|
+
|
361
|
+
[Column("name", Order = 1)]
|
362
|
+
|
363
|
+
public String Name { get; set; }
|
364
|
+
|
365
|
+
#nullable enable
|
366
|
+
|
367
|
+
[Column("test")]
|
368
|
+
|
369
|
+
public string? Test_0001 { get; set; }
|
370
|
+
|
371
|
+
#nullable disable
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
CatModel.cs
|
382
|
+
|
383
|
+
```C#
|
384
|
+
|
385
|
+
using System.Collections.ObjectModel;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
namespace WpfApp1
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
public class CatModel
|
394
|
+
|
395
|
+
{
|
396
|
+
|
397
|
+
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
398
|
+
|
399
|
+
{
|
400
|
+
|
401
|
+
this.IsChecked = false;
|
402
|
+
|
403
|
+
this.Num = Num;
|
404
|
+
|
405
|
+
this.Name = Name;
|
406
|
+
|
407
|
+
this.Test_List = Test_List;
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
public bool IsChecked { get; set; }
|
412
|
+
|
413
|
+
public int Num { get; set; }
|
414
|
+
|
415
|
+
public string Name { get; set; }
|
416
|
+
|
417
|
+
public ObservableCollection<double?> Test_List { get; set; }
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
```
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
PgDbContext.cs
|
428
|
+
|
429
|
+
```C#
|
430
|
+
|
431
|
+
using Npgsql;
|
432
|
+
|
433
|
+
using System.Data.Entity;
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
namespace WpfApp1
|
438
|
+
|
439
|
+
{
|
440
|
+
|
441
|
+
class PgDbContext : DbContext
|
442
|
+
|
443
|
+
{
|
444
|
+
|
445
|
+
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
446
|
+
|
447
|
+
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
448
|
+
|
449
|
+
public DbSet<Cat> Cats { get; set; }
|
450
|
+
|
451
|
+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
452
|
+
|
453
|
+
{
|
454
|
+
|
455
|
+
modelBuilder.HasDefaultSchema("public");
|
456
|
+
|
457
|
+
Database.SetInitializer<PgDbContext>(null);
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
}
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
```
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
### 試したこと
|
470
|
+
|
471
|
+
CreateDataTable()の呼び出し位置をInitializeComponent();の前に移動しました。
|
472
|
+
|
473
|
+
Test_Listの型をListからObservableCollectionに変更しました。
|
474
|
+
|
475
|
+
|
476
|
+
|
29
477
|
調べてみたところ、dataTableの列は正しく追加されて5つになっているにもかかわらず、DataGridは最初の2つの列{Num}, {Name}しか表示されず、残り3つの列{Test_1}, {Test_2}, {Test_3}は表示されていないようです。
|
30
478
|
|
31
479
|
|
@@ -52,454 +500,6 @@
|
|
52
500
|
|
53
501
|
|
54
502
|
|
55
|
-
### 実現したいこと
|
56
|
-
|
57
|
-
たとえDBが空の状態でデータを読み込んでも(一回目の起動で)
|
58
|
-
|
59
|
-
正しくTest_Listの内容を表示できるようにしたいです。
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
### コード
|
64
|
-
|
65
|
-
MainWindow.xaml.cs
|
66
|
-
|
67
|
-
```C#
|
68
|
-
|
69
|
-
using Npgsql;
|
70
|
-
|
71
|
-
using System;
|
72
|
-
|
73
|
-
using System.Collections.Generic;
|
74
|
-
|
75
|
-
using System.Data;
|
76
|
-
|
77
|
-
using System.Linq;
|
78
|
-
|
79
|
-
using System.Text;
|
80
|
-
|
81
|
-
using System.Text.RegularExpressions;
|
82
|
-
|
83
|
-
using System.Windows;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
namespace WpfApp1
|
88
|
-
|
89
|
-
{
|
90
|
-
|
91
|
-
public partial class MainWindow : Window
|
92
|
-
|
93
|
-
{
|
94
|
-
|
95
|
-
public DataTable dataTable { get; } = new DataTable();
|
96
|
-
|
97
|
-
public MainWindow()
|
98
|
-
|
99
|
-
{
|
100
|
-
|
101
|
-
using (var conn = new NpgsqlConnection("Server=localhost; Port=5432; Database=postgres;User Id=postgres;Password=postgres;"))
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
conn.Open();
|
106
|
-
|
107
|
-
using (var command = conn.CreateCommand())
|
108
|
-
|
109
|
-
{
|
110
|
-
|
111
|
-
StringBuilder sb = new StringBuilder();
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
sb.Clear();
|
116
|
-
|
117
|
-
sb.Append("CREATE TABLE IF NOT EXISTS public.tblcat (");
|
118
|
-
|
119
|
-
sb.Append(" num INTEGER NOT NULL");
|
120
|
-
|
121
|
-
sb.Append(" , name VARCHAR(20) NOT NULL");
|
122
|
-
|
123
|
-
sb.Append(" , test VARCHAR(40)");
|
124
|
-
|
125
|
-
sb.Append(" , PRIMARY KEY (num, name)");
|
126
|
-
|
127
|
-
sb.Append(")");
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
command.CommandText = sb.ToString();
|
132
|
-
|
133
|
-
command.ExecuteNonQuery();
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
conn.Close();
|
138
|
-
|
139
|
-
}
|
140
|
-
|
141
|
-
CreateDataTable();
|
142
|
-
|
143
|
-
InitializeComponent();
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
private void CreateDataTable()
|
150
|
-
|
151
|
-
{
|
152
|
-
|
153
|
-
DataColumnCollection columns = dataTable.Columns;
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if (!columns.Contains(nameof(CatModel.Num)))
|
158
|
-
|
159
|
-
{
|
160
|
-
|
161
|
-
DataColumn dataColumn_Num = dataTable.Columns.Add(nameof(CatModel.Num), typeof(int));
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
if (!columns.Contains(nameof(CatModel.Name)))
|
168
|
-
|
169
|
-
{
|
170
|
-
|
171
|
-
DataColumn dataColumn_Name = dataTable.Columns.Add(nameof(CatModel.Name), typeof(string));
|
172
|
-
|
173
|
-
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
using (var context = new PgDbContext())
|
178
|
-
|
179
|
-
{
|
180
|
-
|
181
|
-
var tblCat = context.Cats;
|
182
|
-
|
183
|
-
IQueryable<Cat> result;
|
184
|
-
|
185
|
-
result = from x in tblCat
|
186
|
-
|
187
|
-
select x;
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
int columnCount = 0;
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
foreach (Cat cat in result.ToList())
|
196
|
-
|
197
|
-
{
|
198
|
-
|
199
|
-
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
200
|
-
|
201
|
-
double?[] test_list = numbers.Split(',')
|
202
|
-
|
203
|
-
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
204
|
-
|
205
|
-
.ToArray<double?>();
|
206
|
-
|
207
|
-
columnCount = test_list.Length;
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
for (int i = 0; i < columnCount; i++)
|
214
|
-
|
215
|
-
{
|
216
|
-
|
217
|
-
if (!columns.Contains($"Test_{i + 1}"))
|
218
|
-
|
219
|
-
{
|
220
|
-
|
221
|
-
dataTable.Columns.Add(new DataColumn($"Test_{i + 1}", typeof(int)));
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
} // ここにブレークポイントを貼る
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
foreach (Cat cat in result.ToList())
|
230
|
-
|
231
|
-
{
|
232
|
-
|
233
|
-
var row = dataTable.NewRow();
|
234
|
-
|
235
|
-
row[0] = cat.Num;
|
236
|
-
|
237
|
-
row[1] = cat.Name;
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
242
|
-
|
243
|
-
double?[] test_list = numbers.Split(',')
|
244
|
-
|
245
|
-
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
246
|
-
|
247
|
-
.ToArray<double?>();
|
248
|
-
|
249
|
-
columnCount = test_list.Length;
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
for (int i = 0; i < columnCount; i++)
|
254
|
-
|
255
|
-
{
|
256
|
-
|
257
|
-
row[2 + i] = (test_list[i] == null) ? DBNull.Value : test_list[i];
|
258
|
-
|
259
|
-
}
|
260
|
-
|
261
|
-
dataTable.Rows.Add(row);
|
262
|
-
|
263
|
-
} // ここにブレークポイントを貼る
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
private void imp_button_Click(object sender, RoutedEventArgs e)
|
272
|
-
|
273
|
-
{
|
274
|
-
|
275
|
-
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
276
|
-
|
277
|
-
using (var context = new PgDbContext())
|
278
|
-
|
279
|
-
{
|
280
|
-
|
281
|
-
var table = context.Cats;
|
282
|
-
|
283
|
-
foreach (Cat cat in list)
|
284
|
-
|
285
|
-
{
|
286
|
-
|
287
|
-
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
288
|
-
|
289
|
-
{
|
290
|
-
|
291
|
-
context.Cats.Add(cat);
|
292
|
-
|
293
|
-
context.SaveChanges();
|
294
|
-
|
295
|
-
}
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
}
|
300
|
-
|
301
|
-
CreateDataTable();
|
302
|
-
|
303
|
-
}
|
304
|
-
|
305
|
-
}
|
306
|
-
|
307
|
-
}
|
308
|
-
|
309
|
-
```
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
MainWindow.xaml
|
314
|
-
|
315
|
-
```XAML
|
316
|
-
|
317
|
-
<Window x:Class="WpfApp1.MainWindow"
|
318
|
-
|
319
|
-
x:Name="mainWindow"
|
320
|
-
|
321
|
-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
322
|
-
|
323
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
324
|
-
|
325
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
326
|
-
|
327
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
328
|
-
|
329
|
-
mc:Ignorable="d"
|
330
|
-
|
331
|
-
Title="List" Height="350" Width="750"
|
332
|
-
|
333
|
-
BorderThickness="1">
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
<Grid Width="700" Height="700">
|
338
|
-
|
339
|
-
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding dataTable, ElementName=mainWindow}"
|
340
|
-
|
341
|
-
HorizontalAlignment="Left" Margin="10,10,10,10"/>
|
342
|
-
|
343
|
-
<Button x:Name="imp_button" Content="Import CSV" HorizontalAlignment="Left" Margin="250,273,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="imp_button_Click"/>
|
344
|
-
|
345
|
-
</Grid>
|
346
|
-
|
347
|
-
</Window>
|
348
|
-
|
349
|
-
```
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
Cat.cs
|
354
|
-
|
355
|
-
```C#
|
356
|
-
|
357
|
-
using System;
|
358
|
-
|
359
|
-
using System.ComponentModel.DataAnnotations;
|
360
|
-
|
361
|
-
using System.ComponentModel.DataAnnotations.Schema;
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
namespace WpfApp1
|
366
|
-
|
367
|
-
{
|
368
|
-
|
369
|
-
[Table("tblcat")]
|
370
|
-
|
371
|
-
class Cat
|
372
|
-
|
373
|
-
{
|
374
|
-
|
375
|
-
[Key]
|
376
|
-
|
377
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
378
|
-
|
379
|
-
[Column("num", Order = 2)]
|
380
|
-
|
381
|
-
public int Num { get; set; }
|
382
|
-
|
383
|
-
[Key]
|
384
|
-
|
385
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
386
|
-
|
387
|
-
[Column("name", Order = 1)]
|
388
|
-
|
389
|
-
public String Name { get; set; }
|
390
|
-
|
391
|
-
#nullable enable
|
392
|
-
|
393
|
-
[Column("test")]
|
394
|
-
|
395
|
-
public string? Test_0001 { get; set; }
|
396
|
-
|
397
|
-
#nullable disable
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
}
|
402
|
-
|
403
|
-
```
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
CatModel.cs
|
408
|
-
|
409
|
-
```C#
|
410
|
-
|
411
|
-
using System.Collections.ObjectModel;
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
namespace WpfApp1
|
416
|
-
|
417
|
-
{
|
418
|
-
|
419
|
-
public class CatModel
|
420
|
-
|
421
|
-
{
|
422
|
-
|
423
|
-
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
424
|
-
|
425
|
-
{
|
426
|
-
|
427
|
-
this.IsChecked = false;
|
428
|
-
|
429
|
-
this.Num = Num;
|
430
|
-
|
431
|
-
this.Name = Name;
|
432
|
-
|
433
|
-
this.Test_List = Test_List;
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
public bool IsChecked { get; set; }
|
438
|
-
|
439
|
-
public int Num { get; set; }
|
440
|
-
|
441
|
-
public string Name { get; set; }
|
442
|
-
|
443
|
-
public ObservableCollection<double?> Test_List { get; set; }
|
444
|
-
|
445
|
-
}
|
446
|
-
|
447
|
-
}
|
448
|
-
|
449
|
-
```
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
PgDbContext.cs
|
454
|
-
|
455
|
-
```C#
|
456
|
-
|
457
|
-
using Npgsql;
|
458
|
-
|
459
|
-
using System.Data.Entity;
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
namespace WpfApp1
|
464
|
-
|
465
|
-
{
|
466
|
-
|
467
|
-
class PgDbContext : DbContext
|
468
|
-
|
469
|
-
{
|
470
|
-
|
471
|
-
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
472
|
-
|
473
|
-
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
474
|
-
|
475
|
-
public DbSet<Cat> Cats { get; set; }
|
476
|
-
|
477
|
-
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
478
|
-
|
479
|
-
{
|
480
|
-
|
481
|
-
modelBuilder.HasDefaultSchema("public");
|
482
|
-
|
483
|
-
Database.SetInitializer<PgDbContext>(null);
|
484
|
-
|
485
|
-
}
|
486
|
-
|
487
|
-
}
|
488
|
-
|
489
|
-
}
|
490
|
-
|
491
|
-
```
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
### 試したこと
|
496
|
-
|
497
|
-
CreateDataTable()の呼び出し位置をInitializeComponent();の前に移動しました。
|
498
|
-
|
499
|
-
Test_Listの型をListからObservableCollectionに変更しました。
|
500
|
-
|
501
|
-
|
502
|
-
|
503
503
|
### 補足
|
504
504
|
|
505
505
|
Windows10
|
7
調査結果の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,32 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
調べてみたところ、dataTableの列は正しく追加されて5つになっているにもかかわらず、DataGridは最初の2つの列{Num}, {Name}しか表示されず、残り3つの列{Test_1}, {Test_2}, {Test_3}は表示されていないようです。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
dataTable.Columns.Add(new DataColumn($"Test_{i + 1}", typeof(int)));の2行下の"}"にブレークポイントを貼り、DBを空にした状態で一回目に起動すると、自動変数タブのthis.dataTable.Columns.Results_Viewの[0][1][2][3][4]がそれぞれ{Num}, {Name}, {Test_1}, {Test_2}, {Test_3}と正しく入っていることが確認できました。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
同様に、
|
38
|
+
|
39
|
+
dataTable.Rows.Add(row);の直後の"}"にブレークポイントを貼り、DBを空にした状態で一回目に起動すると、自動変数タブのthis.dataTable.Rows.Results_View.[0].ItemArrayの[0][1][2][3][4]がそれぞれ1, "AA", 1, 2, 3と正しく入っていることが確認できました。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
しかし、そのままContinueすると、{Num}, {Name}の列は正しく表示されるのですが、Test_Listの部分の{Test_1}, {Test_2}, {Test_3}は表示されません。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
つまり、dataTableには行・列ともに正しくデータが入っているにもかかわらず、Test_Listの部分がDataGridに表示されません。
|
48
|
+
|
49
|
+
これは何が原因と考えられますか?
|
50
|
+
|
51
|
+
どのように確認すればよいですか?
|
52
|
+
|
53
|
+
|
54
|
+
|
29
55
|
### 実現したいこと
|
30
56
|
|
31
57
|
たとえDBが空の状態でデータを読み込んでも(一回目の起動で)
|
@@ -196,86 +222,226 @@
|
|
196
222
|
|
197
223
|
}
|
198
224
|
|
225
|
+
} // ここにブレークポイントを貼る
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
foreach (Cat cat in result.ToList())
|
230
|
+
|
231
|
+
{
|
232
|
+
|
233
|
+
var row = dataTable.NewRow();
|
234
|
+
|
235
|
+
row[0] = cat.Num;
|
236
|
+
|
237
|
+
row[1] = cat.Name;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
242
|
+
|
243
|
+
double?[] test_list = numbers.Split(',')
|
244
|
+
|
245
|
+
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
246
|
+
|
247
|
+
.ToArray<double?>();
|
248
|
+
|
249
|
+
columnCount = test_list.Length;
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
for (int i = 0; i < columnCount; i++)
|
254
|
+
|
255
|
+
{
|
256
|
+
|
257
|
+
row[2 + i] = (test_list[i] == null) ? DBNull.Value : test_list[i];
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
dataTable.Rows.Add(row);
|
262
|
+
|
263
|
+
} // ここにブレークポイントを貼る
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
private void imp_button_Click(object sender, RoutedEventArgs e)
|
272
|
+
|
273
|
+
{
|
274
|
+
|
275
|
+
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
276
|
+
|
277
|
+
using (var context = new PgDbContext())
|
278
|
+
|
279
|
+
{
|
280
|
+
|
281
|
+
var table = context.Cats;
|
282
|
+
|
283
|
+
foreach (Cat cat in list)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
context.Cats.Add(cat);
|
292
|
+
|
293
|
+
context.SaveChanges();
|
294
|
+
|
295
|
+
}
|
296
|
+
|
199
297
|
}
|
200
298
|
|
201
|
-
|
202
|
-
|
203
|
-
foreach (Cat cat in result.ToList())
|
204
|
-
|
205
|
-
{
|
206
|
-
|
207
|
-
var row = dataTable.NewRow();
|
208
|
-
|
209
|
-
row[0] = cat.Num;
|
210
|
-
|
211
|
-
row[1] = cat.Name;
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
216
|
-
|
217
|
-
double?[] test_list = numbers.Split(',')
|
218
|
-
|
219
|
-
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
220
|
-
|
221
|
-
.ToArray<double?>();
|
222
|
-
|
223
|
-
columnCount = test_list.Length;
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
for (int i = 0; i < columnCount; i++)
|
228
|
-
|
229
|
-
{
|
230
|
-
|
231
|
-
row[2 + i] = (test_list[i] == null) ? DBNull.Value : test_list[i];
|
232
|
-
|
233
|
-
}
|
234
|
-
|
235
|
-
dataTable.Rows.Add(row);
|
236
|
-
|
237
|
-
}
|
238
|
-
|
239
299
|
}
|
240
300
|
|
301
|
+
CreateDataTable();
|
302
|
+
|
241
303
|
}
|
242
304
|
|
243
|
-
|
305
|
+
}
|
306
|
+
|
244
|
-
|
307
|
+
}
|
308
|
+
|
309
|
+
```
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
MainWindow.xaml
|
314
|
+
|
315
|
+
```XAML
|
316
|
+
|
317
|
+
<Window x:Class="WpfApp1.MainWindow"
|
318
|
+
|
319
|
+
x:Name="mainWindow"
|
320
|
+
|
321
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
322
|
+
|
323
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
324
|
+
|
325
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
326
|
+
|
327
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
328
|
+
|
329
|
+
mc:Ignorable="d"
|
330
|
+
|
331
|
+
Title="List" Height="350" Width="750"
|
332
|
+
|
333
|
+
BorderThickness="1">
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
<Grid Width="700" Height="700">
|
338
|
+
|
339
|
+
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding dataTable, ElementName=mainWindow}"
|
340
|
+
|
341
|
+
HorizontalAlignment="Left" Margin="10,10,10,10"/>
|
342
|
+
|
343
|
+
<Button x:Name="imp_button" Content="Import CSV" HorizontalAlignment="Left" Margin="250,273,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="imp_button_Click"/>
|
344
|
+
|
345
|
+
</Grid>
|
346
|
+
|
347
|
+
</Window>
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
Cat.cs
|
354
|
+
|
355
|
+
```C#
|
356
|
+
|
357
|
+
using System;
|
358
|
+
|
359
|
+
using System.ComponentModel.DataAnnotations;
|
360
|
+
|
361
|
+
using System.ComponentModel.DataAnnotations.Schema;
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
namespace WpfApp1
|
366
|
+
|
367
|
+
{
|
368
|
+
|
369
|
+
[Table("tblcat")]
|
370
|
+
|
371
|
+
class Cat
|
372
|
+
|
373
|
+
{
|
374
|
+
|
375
|
+
[Key]
|
376
|
+
|
377
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
378
|
+
|
379
|
+
[Column("num", Order = 2)]
|
380
|
+
|
381
|
+
public int Num { get; set; }
|
382
|
+
|
383
|
+
[Key]
|
384
|
+
|
385
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
386
|
+
|
387
|
+
[Column("name", Order = 1)]
|
388
|
+
|
389
|
+
public String Name { get; set; }
|
390
|
+
|
391
|
+
#nullable enable
|
392
|
+
|
393
|
+
[Column("test")]
|
394
|
+
|
395
|
+
public string? Test_0001 { get; set; }
|
396
|
+
|
397
|
+
#nullable disable
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
```
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
CatModel.cs
|
408
|
+
|
409
|
+
```C#
|
410
|
+
|
411
|
+
using System.Collections.ObjectModel;
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
namespace WpfApp1
|
416
|
+
|
417
|
+
{
|
418
|
+
|
419
|
+
public class CatModel
|
420
|
+
|
421
|
+
{
|
422
|
+
|
245
|
-
p
|
423
|
+
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
246
424
|
|
247
425
|
{
|
248
426
|
|
249
|
-
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
250
|
-
|
251
|
-
|
427
|
+
this.IsChecked = false;
|
252
|
-
|
428
|
+
|
253
|
-
|
429
|
+
this.Num = Num;
|
254
|
-
|
430
|
+
|
255
|
-
|
431
|
+
this.Name = Name;
|
256
|
-
|
432
|
+
|
257
|
-
|
433
|
+
this.Test_List = Test_List;
|
258
|
-
|
259
|
-
{
|
260
|
-
|
261
|
-
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
262
|
-
|
263
|
-
{
|
264
|
-
|
265
|
-
context.Cats.Add(cat);
|
266
|
-
|
267
|
-
context.SaveChanges();
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
}
|
274
|
-
|
275
|
-
CreateDataTable();
|
276
434
|
|
277
435
|
}
|
278
436
|
|
437
|
+
public bool IsChecked { get; set; }
|
438
|
+
|
439
|
+
public int Num { get; set; }
|
440
|
+
|
441
|
+
public string Name { get; set; }
|
442
|
+
|
443
|
+
public ObservableCollection<double?> Test_List { get; set; }
|
444
|
+
|
279
445
|
}
|
280
446
|
|
281
447
|
}
|
@@ -284,188 +450,48 @@
|
|
284
450
|
|
285
451
|
|
286
452
|
|
287
|
-
|
453
|
+
PgDbContext.cs
|
288
|
-
|
454
|
+
|
289
|
-
```
|
455
|
+
```C#
|
290
|
-
|
291
|
-
|
456
|
+
|
292
|
-
|
293
|
-
|
457
|
+
using Npgsql;
|
294
|
-
|
295
|
-
|
458
|
+
|
296
|
-
|
297
|
-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
298
|
-
|
299
|
-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
300
|
-
|
301
|
-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
302
|
-
|
303
|
-
|
459
|
+
using System.Data.Entity;
|
460
|
+
|
461
|
+
|
462
|
+
|
304
|
-
|
463
|
+
namespace WpfApp1
|
464
|
+
|
465
|
+
{
|
466
|
+
|
467
|
+
class PgDbContext : DbContext
|
468
|
+
|
469
|
+
{
|
470
|
+
|
471
|
+
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
472
|
+
|
473
|
+
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
474
|
+
|
475
|
+
public DbSet<Cat> Cats { get; set; }
|
476
|
+
|
305
|
-
|
477
|
+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
306
|
-
|
478
|
+
|
307
|
-
|
479
|
+
{
|
308
|
-
|
309
|
-
|
310
|
-
|
480
|
+
|
311
|
-
|
481
|
+
modelBuilder.HasDefaultSchema("public");
|
312
|
-
|
313
|
-
|
482
|
+
|
314
|
-
|
315
|
-
|
483
|
+
Database.SetInitializer<PgDbContext>(null);
|
316
|
-
|
317
|
-
|
484
|
+
|
318
|
-
|
319
|
-
|
485
|
+
}
|
320
|
-
|
486
|
+
|
321
|
-
|
487
|
+
}
|
488
|
+
|
489
|
+
}
|
322
490
|
|
323
491
|
```
|
324
492
|
|
325
493
|
|
326
494
|
|
327
|
-
Cat.cs
|
328
|
-
|
329
|
-
```C#
|
330
|
-
|
331
|
-
using System;
|
332
|
-
|
333
|
-
using System.ComponentModel.DataAnnotations;
|
334
|
-
|
335
|
-
using System.ComponentModel.DataAnnotations.Schema;
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
namespace WpfApp1
|
340
|
-
|
341
|
-
{
|
342
|
-
|
343
|
-
[Table("tblcat")]
|
344
|
-
|
345
|
-
class Cat
|
346
|
-
|
347
|
-
{
|
348
|
-
|
349
|
-
[Key]
|
350
|
-
|
351
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
352
|
-
|
353
|
-
[Column("num", Order = 2)]
|
354
|
-
|
355
|
-
public int Num { get; set; }
|
356
|
-
|
357
|
-
[Key]
|
358
|
-
|
359
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
360
|
-
|
361
|
-
[Column("name", Order = 1)]
|
362
|
-
|
363
|
-
public String Name { get; set; }
|
364
|
-
|
365
|
-
#nullable enable
|
366
|
-
|
367
|
-
[Column("test")]
|
368
|
-
|
369
|
-
public string? Test_0001 { get; set; }
|
370
|
-
|
371
|
-
#nullable disable
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
}
|
376
|
-
|
377
|
-
```
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
CatModel.cs
|
382
|
-
|
383
|
-
```C#
|
384
|
-
|
385
|
-
using System.Collections.ObjectModel;
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
namespace WpfApp1
|
390
|
-
|
391
|
-
{
|
392
|
-
|
393
|
-
public class CatModel
|
394
|
-
|
395
|
-
{
|
396
|
-
|
397
|
-
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
398
|
-
|
399
|
-
{
|
400
|
-
|
401
|
-
this.IsChecked = false;
|
402
|
-
|
403
|
-
this.Num = Num;
|
404
|
-
|
405
|
-
this.Name = Name;
|
406
|
-
|
407
|
-
this.Test_List = Test_List;
|
408
|
-
|
409
|
-
}
|
410
|
-
|
411
|
-
public bool IsChecked { get; set; }
|
412
|
-
|
413
|
-
public int Num { get; set; }
|
414
|
-
|
415
|
-
public string Name { get; set; }
|
416
|
-
|
417
|
-
public ObservableCollection<double?> Test_List { get; set; }
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
}
|
422
|
-
|
423
|
-
```
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
PgDbContext.cs
|
428
|
-
|
429
|
-
```C#
|
430
|
-
|
431
|
-
using Npgsql;
|
432
|
-
|
433
|
-
using System.Data.Entity;
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
namespace WpfApp1
|
438
|
-
|
439
|
-
{
|
440
|
-
|
441
|
-
class PgDbContext : DbContext
|
442
|
-
|
443
|
-
{
|
444
|
-
|
445
|
-
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
446
|
-
|
447
|
-
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
448
|
-
|
449
|
-
public DbSet<Cat> Cats { get; set; }
|
450
|
-
|
451
|
-
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
452
|
-
|
453
|
-
{
|
454
|
-
|
455
|
-
modelBuilder.HasDefaultSchema("public");
|
456
|
-
|
457
|
-
Database.SetInitializer<PgDbContext>(null);
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
}
|
462
|
-
|
463
|
-
}
|
464
|
-
|
465
|
-
```
|
466
|
-
|
467
|
-
|
468
|
-
|
469
495
|
### 試したこと
|
470
496
|
|
471
497
|
CreateDataTable()の呼び出し位置をInitializeComponent();の前に移動しました。
|
6
DataTableに内容が表示されない→DataGridに内容が表示されない
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
データ読込直後はData
|
1
|
+
データ読込直後はDataGridに内容が表示されない
|
test
CHANGED
File without changes
|
5
DataTableに表示→DataGridに表示
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提
|
2
2
|
|
3
|
-
CSVデータをPostgreSQLデータベースに読み込み、その内容をData
|
3
|
+
CSVデータをPostgreSQLデータベースに読み込み、その内容をDataGridに表示するプログラムです。
|
4
4
|
|
5
5
|
データの読み込みは`Import CSV`ボタンで行います。
|
6
6
|
|
@@ -506,6 +506,6 @@
|
|
506
506
|
|
507
507
|
|
508
508
|
|
509
|
-
また、Data
|
509
|
+
また、DataTableを導入した理由は、
|
510
510
|
|
511
511
|
実行時に任意の数の列を追加するためです。
|
4
訂正: 任意の数の桁 →任意の数の列
test
CHANGED
File without changes
|
test
CHANGED
@@ -508,4 +508,4 @@
|
|
508
508
|
|
509
509
|
また、DataGridをやめてDataTableを導入した理由は、
|
510
510
|
|
511
|
-
実行時に任意の数の
|
511
|
+
実行時に任意の数の列を追加するためです。
|
3
コードを削減し、説明を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,11 +1,67 @@
|
|
1
|
+
### 前提
|
2
|
+
|
3
|
+
CSVデータをPostgreSQLデータベースに読み込み、その内容をDataTableに表示するプログラムです。
|
4
|
+
|
5
|
+
データの読み込みは`Import CSV`ボタンで行います。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
データは
|
10
|
+
|
11
|
+
> 1,AA,"{1,2,3}"
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
のようなCSV形式で、データの後半"{1,2,3}"をTest_Listと呼んでいます。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
### 問題
|
20
|
+
|
1
|
-
DBが空で
|
21
|
+
DBが空の状態でデータを読み込むとTest_Listの内容が表示されません。
|
2
|
-
|
22
|
+
|
3
|
-
データが読み込まれた状態で起動すると
|
23
|
+
なぜか一度DBにデータが読み込まれた状態で一旦終了し再起動することで
|
24
|
+
|
25
|
+
初めてTest_Listの内容が表示されます。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
### 実現したいこと
|
30
|
+
|
31
|
+
たとえDBが空の状態でデータを読み込んでも(一回目の起動で)
|
32
|
+
|
33
|
+
正しくTest_Listの内容を表示できるようにしたいです。
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
### コード
|
4
38
|
|
5
39
|
MainWindow.xaml.cs
|
6
40
|
|
7
41
|
```C#
|
8
42
|
|
43
|
+
using Npgsql;
|
44
|
+
|
45
|
+
using System;
|
46
|
+
|
47
|
+
using System.Collections.Generic;
|
48
|
+
|
49
|
+
using System.Data;
|
50
|
+
|
51
|
+
using System.Linq;
|
52
|
+
|
53
|
+
using System.Text;
|
54
|
+
|
55
|
+
using System.Text.RegularExpressions;
|
56
|
+
|
57
|
+
using System.Windows;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
namespace WpfApp1
|
62
|
+
|
63
|
+
{
|
64
|
+
|
9
65
|
public partial class MainWindow : Window
|
10
66
|
|
11
67
|
{
|
@@ -58,8 +114,6 @@
|
|
58
114
|
|
59
115
|
CreateDataTable();
|
60
116
|
|
61
|
-
Actual_Search();
|
62
|
-
|
63
117
|
InitializeComponent();
|
64
118
|
|
65
119
|
}
|
@@ -188,314 +242,270 @@
|
|
188
242
|
|
189
243
|
|
190
244
|
|
191
|
-
private void
|
245
|
+
private void imp_button_Click(object sender, RoutedEventArgs e)
|
192
246
|
|
193
247
|
{
|
194
248
|
|
249
|
+
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
250
|
+
|
195
|
-
|
251
|
+
using (var context = new PgDbContext())
|
252
|
+
|
196
|
-
|
253
|
+
{
|
254
|
+
|
197
|
-
|
255
|
+
var table = context.Cats;
|
256
|
+
|
198
|
-
|
257
|
+
foreach (Cat cat in list)
|
258
|
+
|
259
|
+
{
|
260
|
+
|
199
|
-
|
261
|
+
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
262
|
+
|
200
|
-
|
263
|
+
{
|
264
|
+
|
265
|
+
context.Cats.Add(cat);
|
266
|
+
|
201
|
-
|
267
|
+
context.SaveChanges();
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
CreateDataTable();
|
202
276
|
|
203
277
|
}
|
204
278
|
|
205
|
-
|
279
|
+
}
|
280
|
+
|
206
|
-
|
281
|
+
}
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
MainWindow.xaml
|
288
|
+
|
289
|
+
```XAML
|
290
|
+
|
291
|
+
<Window x:Class="WpfApp1.MainWindow"
|
292
|
+
|
293
|
+
x:Name="mainWindow"
|
294
|
+
|
295
|
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
296
|
+
|
297
|
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
298
|
+
|
299
|
+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
300
|
+
|
301
|
+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
302
|
+
|
303
|
+
mc:Ignorable="d"
|
304
|
+
|
305
|
+
Title="List" Height="350" Width="750"
|
306
|
+
|
307
|
+
BorderThickness="1">
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
<Grid Width="700" Height="700">
|
312
|
+
|
313
|
+
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding dataTable, ElementName=mainWindow}"
|
314
|
+
|
315
|
+
HorizontalAlignment="Left" Margin="10,10,10,10"/>
|
316
|
+
|
317
|
+
<Button x:Name="imp_button" Content="Import CSV" HorizontalAlignment="Left" Margin="250,273,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="imp_button_Click"/>
|
318
|
+
|
319
|
+
</Grid>
|
320
|
+
|
321
|
+
</Window>
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
Cat.cs
|
328
|
+
|
329
|
+
```C#
|
330
|
+
|
331
|
+
using System;
|
332
|
+
|
333
|
+
using System.ComponentModel.DataAnnotations;
|
334
|
+
|
335
|
+
using System.ComponentModel.DataAnnotations.Schema;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
namespace WpfApp1
|
340
|
+
|
341
|
+
{
|
342
|
+
|
343
|
+
[Table("tblcat")]
|
344
|
+
|
345
|
+
class Cat
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
[Key]
|
350
|
+
|
351
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
352
|
+
|
353
|
+
[Column("num", Order = 2)]
|
354
|
+
|
207
|
-
p
|
355
|
+
public int Num { get; set; }
|
356
|
+
|
357
|
+
[Key]
|
358
|
+
|
359
|
+
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
360
|
+
|
361
|
+
[Column("name", Order = 1)]
|
362
|
+
|
363
|
+
public String Name { get; set; }
|
364
|
+
|
365
|
+
#nullable enable
|
366
|
+
|
367
|
+
[Column("test")]
|
368
|
+
|
369
|
+
public string? Test_0001 { get; set; }
|
370
|
+
|
371
|
+
#nullable disable
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
CatModel.cs
|
382
|
+
|
383
|
+
```C#
|
384
|
+
|
385
|
+
using System.Collections.ObjectModel;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
namespace WpfApp1
|
390
|
+
|
391
|
+
{
|
392
|
+
|
393
|
+
public class CatModel
|
394
|
+
|
395
|
+
{
|
396
|
+
|
397
|
+
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
208
398
|
|
209
399
|
{
|
210
400
|
|
211
|
-
using (var context = new PgDbContext())
|
212
|
-
|
213
|
-
{
|
214
|
-
|
215
|
-
|
401
|
+
this.IsChecked = false;
|
216
|
-
|
402
|
+
|
217
|
-
|
403
|
+
this.Num = Num;
|
218
|
-
|
404
|
+
|
219
|
-
|
405
|
+
this.Name = Name;
|
220
|
-
|
221
|
-
|
406
|
+
|
222
|
-
|
223
|
-
|
407
|
+
this.Test_List = Test_List;
|
224
|
-
|
225
|
-
}
|
226
408
|
|
227
409
|
}
|
228
410
|
|
229
|
-
|
411
|
+
public bool IsChecked { get; set; }
|
412
|
+
|
230
|
-
|
413
|
+
public int Num { get; set; }
|
414
|
+
|
415
|
+
public string Name { get; set; }
|
416
|
+
|
417
|
+
public ObservableCollection<double?> Test_List { get; set; }
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
```
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
PgDbContext.cs
|
428
|
+
|
429
|
+
```C#
|
430
|
+
|
431
|
+
using Npgsql;
|
432
|
+
|
433
|
+
using System.Data.Entity;
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
namespace WpfApp1
|
438
|
+
|
439
|
+
{
|
440
|
+
|
441
|
+
class PgDbContext : DbContext
|
442
|
+
|
443
|
+
{
|
444
|
+
|
445
|
+
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
446
|
+
|
447
|
+
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
448
|
+
|
449
|
+
public DbSet<Cat> Cats { get; set; }
|
450
|
+
|
231
|
-
pr
|
451
|
+
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
232
452
|
|
233
453
|
{
|
234
454
|
|
235
|
-
using (var context = new PgDbContext())
|
236
|
-
|
237
|
-
{
|
238
|
-
|
239
|
-
var tblCat = context.Cats;
|
240
|
-
|
241
|
-
IQueryable<Cat> result;
|
242
|
-
|
243
|
-
result = from x in tblCat
|
244
|
-
|
245
|
-
select x;
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
List<CatModel> resultList = new List<CatModel>();
|
250
|
-
|
251
|
-
foreach (Cat cat in result.ToList())
|
252
|
-
|
253
|
-
{
|
254
|
-
|
255
|
-
var numbers = Regex.Match(cat.Test_0001, @"\{(?<numbers>[\d+,]+)\}").Groups["numbers"].Value;
|
256
|
-
|
257
|
-
double?[] test_ = numbers.Split(',')
|
258
|
-
|
259
|
-
.Select(x => String.IsNullOrEmpty(x) ? null : (double?)double.Parse(x))
|
260
|
-
|
261
|
-
.ToArray();
|
262
|
-
|
263
|
-
List<double?> test_list = test_.ToList<double?>();
|
264
|
-
|
265
|
-
|
455
|
+
modelBuilder.HasDefaultSchema("public");
|
266
|
-
|
267
|
-
|
456
|
+
|
268
|
-
|
269
|
-
|
457
|
+
Database.SetInitializer<PgDbContext>(null);
|
270
|
-
|
271
|
-
}
|
272
|
-
|
273
|
-
e.Result = resultList;
|
274
|
-
|
275
|
-
}
|
276
458
|
|
277
459
|
}
|
278
460
|
|
279
|
-
|
280
|
-
|
281
|
-
private void SearchProcessCompleted(object sender, RunWorkerCompletedEventArgs e)
|
282
|
-
|
283
|
-
{
|
284
|
-
|
285
|
-
this.dataGrid.ItemsSource = e.Result as List<CatModel>;
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
private void imp_button_Click(object sender, RoutedEventArgs e)
|
292
|
-
|
293
|
-
{
|
294
|
-
|
295
|
-
List<Cat> list = new List<Cat>() { new Cat() { Num=1, Name="AA", Test_0001="{1,2,3}"} };
|
296
|
-
|
297
|
-
using (var context = new PgDbContext())
|
298
|
-
|
299
|
-
{
|
300
|
-
|
301
|
-
var table = context.Cats;
|
302
|
-
|
303
|
-
foreach (Cat cat in list)
|
304
|
-
|
305
|
-
{
|
306
|
-
|
307
|
-
if (table.SingleOrDefault(x => x.Num == cat.Num) == null)
|
308
|
-
|
309
|
-
{
|
310
|
-
|
311
|
-
context.Cats.Add(cat);
|
312
|
-
|
313
|
-
context.SaveChanges();
|
314
|
-
|
315
|
-
}
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
CreateDataTable();
|
322
|
-
|
323
|
-
searchData();
|
324
|
-
|
325
|
-
Actual_Search();
|
326
|
-
|
327
|
-
}
|
328
|
-
|
329
461
|
}
|
330
462
|
|
463
|
+
}
|
464
|
+
|
331
465
|
```
|
332
466
|
|
333
467
|
|
334
468
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
</DataGridTemplateColumn.CellTemplate>
|
380
|
-
|
381
|
-
</DataGridTemplateColumn>
|
382
|
-
|
383
|
-
<DataGridTextColumn Binding="{Binding Num}" ClipboardContentBinding="{x:Null}" Header="Num" Width="50"/>
|
384
|
-
|
385
|
-
<DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Name" Width="100"/>
|
386
|
-
|
387
|
-
<DataGridTextColumn Binding="{Binding Test_List}" ClipboardContentBinding="{x:Null}" Header="Test_List" Width="*"/>
|
388
|
-
|
389
|
-
</DataGrid.Columns>
|
390
|
-
|
391
|
-
</DataGrid>
|
392
|
-
|
393
|
-
<Button x:Name="imp_button" Content="Import CSV" HorizontalAlignment="Left" Margin="250,273,0,0" VerticalAlignment="Top" Width="75" Height="30" Click="imp_button_Click"/>
|
394
|
-
|
395
|
-
</Grid>
|
396
|
-
|
397
|
-
</Window>
|
398
|
-
|
399
|
-
```
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
Cat.cs
|
404
|
-
|
405
|
-
```C#
|
406
|
-
|
407
|
-
[Table("tblcat")]
|
408
|
-
|
409
|
-
class Cat
|
410
|
-
|
411
|
-
{
|
412
|
-
|
413
|
-
[Key]
|
414
|
-
|
415
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
416
|
-
|
417
|
-
[Column("num", Order = 2)]
|
418
|
-
|
419
|
-
public int Num { get; set; }
|
420
|
-
|
421
|
-
[Key]
|
422
|
-
|
423
|
-
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
424
|
-
|
425
|
-
[Column("name", Order = 1)]
|
426
|
-
|
427
|
-
public String Name { get; set; }
|
428
|
-
|
429
|
-
[Column("test")]
|
430
|
-
|
431
|
-
public string? Test_0001 { get; set; }
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
```
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
CatModel.cs
|
440
|
-
|
441
|
-
```C#
|
442
|
-
|
443
|
-
public class CatModel
|
444
|
-
|
445
|
-
{
|
446
|
-
|
447
|
-
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
448
|
-
|
449
|
-
{
|
450
|
-
|
451
|
-
this.IsChecked = false;
|
452
|
-
|
453
|
-
this.Num = Num;
|
454
|
-
|
455
|
-
this.Name = Name;
|
456
|
-
|
457
|
-
this.Test_List = Test_List;
|
458
|
-
|
459
|
-
}
|
460
|
-
|
461
|
-
public bool IsChecked { get; set; }
|
462
|
-
|
463
|
-
public int Num { get; set; }
|
464
|
-
|
465
|
-
public string Name { get; set; }
|
466
|
-
|
467
|
-
public ObservableCollection<double?> Test_List { get; set; }
|
468
|
-
|
469
|
-
}
|
470
|
-
|
471
|
-
```
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
PgDbContext.cs
|
476
|
-
|
477
|
-
```C#
|
478
|
-
|
479
|
-
class PgDbContext : DbContext
|
480
|
-
|
481
|
-
{
|
482
|
-
|
483
|
-
private const string ConnectionString = "Server=localhost;User ID=postgres;Password=postgres;Database=postgres;port=5432";
|
484
|
-
|
485
|
-
public PgDbContext() : base(new NpgsqlConnection(ConnectionString), true) { }
|
486
|
-
|
487
|
-
public DbSet<Cat> Cats { get; set; }
|
488
|
-
|
489
|
-
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
490
|
-
|
491
|
-
{
|
492
|
-
|
493
|
-
modelBuilder.HasDefaultSchema("public");
|
494
|
-
|
495
|
-
Database.SetInitializer<PgDbContext>(null);
|
496
|
-
|
497
|
-
}
|
498
|
-
|
499
|
-
}
|
500
|
-
|
501
|
-
```
|
469
|
+
### 試したこと
|
470
|
+
|
471
|
+
CreateDataTable()の呼び出し位置をInitializeComponent();の前に移動しました。
|
472
|
+
|
473
|
+
Test_Listの型をListからObservableCollectionに変更しました。
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
### 補足
|
478
|
+
|
479
|
+
Windows10
|
480
|
+
|
481
|
+
C# .NET Core5.0
|
482
|
+
|
483
|
+
VisualStudio2019
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
PostgreSQLのDB名、ユーザー名、パスワードは共にpostgres
|
488
|
+
|
489
|
+
スキーマはpublic
|
490
|
+
|
491
|
+
|
492
|
+
|
493
|
+
今回使ったTest_Listデータは"{1,2,3}"のように3つしかありませんが、
|
494
|
+
|
495
|
+
最終的には"{1,2,3,...,4998,4999,5000}"のように5,000列入力する予定です。
|
496
|
+
|
497
|
+
PostgreSQLの列数の上限は1,600列までであり、
|
498
|
+
|
499
|
+
通常のCSV形式"1,2,3,...,4998,4999,5000"では上限を超えてしまい、エラーになります。
|
500
|
+
|
501
|
+
そこで、Test_Listを1つの配列型"{1,2,3,...,4998,4999,5000}"で定義することで、
|
502
|
+
|
503
|
+
PostgreSQL上の列数は1つ(Excelで言うところのセル1つ)のみになり、上限を超えずに済みます。
|
504
|
+
|
505
|
+
その代わり、DataTable側で読み込む際に分解してやる必要がある訳です。
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
また、DataGridをやめてDataTableを導入した理由は、
|
510
|
+
|
511
|
+
実行時に任意の数の桁を追加するためです。
|
2
List -> ObservableCollection
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,18 +1,6 @@
|
|
1
|
-
DBが空の状態で
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
> 1,AA,"{1,2,3}"
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
DBが空でImport CSVでデータを読み込むとTest_Listの内容が表示されない
|
10
|
-
|
2
|
+
|
11
|
-
データが読み込まれた状態で起動すると
|
3
|
+
データが読み込まれた状態で起動すると内容が表示される
|
12
|
-
|
13
|
-
DBが空の状態でデータを読み込んでも内容を表示できるようにしたい。
|
14
|
-
|
15
|
-
|
16
4
|
|
17
5
|
MainWindow.xaml.cs
|
18
6
|
|
@@ -274,7 +262,11 @@
|
|
274
262
|
|
275
263
|
List<double?> test_list = test_.ToList<double?>();
|
276
264
|
|
265
|
+
var oc = new ObservableCollection<double?>();
|
266
|
+
|
267
|
+
test_list.ForEach(x => oc.Add(x));
|
268
|
+
|
277
|
-
resultList.Add(new CatModel(cat.Num, cat.Name,
|
269
|
+
resultList.Add(new CatModel(cat.Num, cat.Name, oc));
|
278
270
|
|
279
271
|
}
|
280
272
|
|
@@ -366,21 +358,15 @@
|
|
366
358
|
|
367
359
|
<Grid Width="700" Height="700">
|
368
360
|
|
369
|
-
<DataGrid IsReadOnly="True"
|
370
|
-
|
371
|
-
AutoGenerateColumns="True"
|
372
|
-
|
373
|
-
|
361
|
+
<DataGrid AutoGenerateColumns="True" ItemsSource="{Binding dataTable, ElementName=mainWindow}"
|
374
|
-
|
375
|
-
|
362
|
+
|
376
|
-
|
377
|
-
Margin="10,10,10,10"/>
|
363
|
+
HorizontalAlignment="Left" Margin="10,10,10,10"/>
|
378
364
|
|
379
365
|
<DataGrid AutoGenerateColumns="False" Name="dataGrid" HorizontalAlignment="Left" Margin="10,125,0,439" Width="650">
|
380
366
|
|
381
367
|
<DataGrid.Columns>
|
382
368
|
|
383
|
-
<DataGridTemplateColumn
|
369
|
+
<DataGridTemplateColumn Header="Select" Width="50">
|
384
370
|
|
385
371
|
<DataGridTemplateColumn.CellTemplate>
|
386
372
|
|
@@ -394,11 +380,11 @@
|
|
394
380
|
|
395
381
|
</DataGridTemplateColumn>
|
396
382
|
|
397
|
-
<DataGridTextColumn Binding="{Binding Num}" ClipboardContentBinding="{x:Null}" Header="Num"
|
383
|
+
<DataGridTextColumn Binding="{Binding Num}" ClipboardContentBinding="{x:Null}" Header="Num" Width="50"/>
|
398
|
-
|
384
|
+
|
399
|
-
<DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Name"
|
385
|
+
<DataGridTextColumn Binding="{Binding Name}" ClipboardContentBinding="{x:Null}" Header="Name" Width="100"/>
|
400
|
-
|
386
|
+
|
401
|
-
<DataGridTextColumn Binding="{Binding Test_List}" ClipboardContentBinding="{x:Null}" Header="Test_List"
|
387
|
+
<DataGridTextColumn Binding="{Binding Test_List}" ClipboardContentBinding="{x:Null}" Header="Test_List" Width="*"/>
|
402
388
|
|
403
389
|
</DataGrid.Columns>
|
404
390
|
|
@@ -458,7 +444,7 @@
|
|
458
444
|
|
459
445
|
{
|
460
446
|
|
461
|
-
public CatModel(int Num,
|
447
|
+
public CatModel(int Num, string Name, ObservableCollection<double?> Test_List)
|
462
448
|
|
463
449
|
{
|
464
450
|
|
@@ -472,13 +458,13 @@
|
|
472
458
|
|
473
459
|
}
|
474
460
|
|
475
|
-
public
|
461
|
+
public bool IsChecked { get; set; }
|
476
462
|
|
477
463
|
public int Num { get; set; }
|
478
464
|
|
479
|
-
public
|
465
|
+
public string Name { get; set; }
|
480
|
-
|
466
|
+
|
481
|
-
public
|
467
|
+
public ObservableCollection<double?> Test_List { get; set; }
|
482
468
|
|
483
469
|
}
|
484
470
|
|
@@ -513,9 +499,3 @@
|
|
513
499
|
}
|
514
500
|
|
515
501
|
```
|
516
|
-
|
517
|
-
### 補足
|
518
|
-
|
519
|
-
データ読込はImport CSVボタン
|
520
|
-
|
521
|
-
下のDataGridは後で消す
|
1
10,000字の制限で書けなかった補足を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -514,6 +514,8 @@
|
|
514
514
|
|
515
515
|
```
|
516
516
|
|
517
|
-
###
|
517
|
+
### 補足
|
518
|
-
|
518
|
+
|
519
|
-
|
519
|
+
データ読込はImport CSVボタン
|
520
|
+
|
521
|
+
下のDataGridは後で消す
|