回答編集履歴

3

見直しキャンペーン中

2023/07/20 14:25

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -1,223 +1,112 @@
1
1
  リンク記事は配列の配列(ジャグ配列)をDataGridに表示する例ですね(あまり使うことはなさそうですが)
2
-
3
2
  xamlが記事通りだとすると`List<string>`(list_param)が`List<char[]>`のように扱われてしまいます。
4
3
 
5
-
6
-
7
4
  * xamlを変える(回答コードのDataGrid_CSV1・FileRead1)
8
-
9
5
  * 段階を踏まず全部出す(回答コードのDataGrid_CSV2・FileRead2)
10
-
11
-
12
6
 
13
7
  かでしょうか。
14
8
 
15
-
16
-
17
- ```xaml
9
+ ```xml
18
-
19
10
  <Window
20
-
21
11
  x:Class="Questions241547.MainWindow"
22
-
23
12
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
24
-
25
13
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
26
-
27
14
  Width="800"
28
-
29
15
  Height="450">
30
-
31
16
  <Grid>
32
-
33
17
  <Grid.RowDefinitions>
34
-
35
18
  <RowDefinition />
36
-
37
19
  <RowDefinition />
38
-
39
20
  </Grid.RowDefinitions>
40
21
 
41
-
42
-
43
22
  <DataGrid x:Name="DataGrid_CSV1" AutoGenerateColumns="False">
44
-
45
23
  <DataGrid.Columns>
46
-
47
24
  <DataGridTextColumn Binding="{Binding}" Header="Col1" />
48
-
49
25
  <!--<DataGridTextColumn Binding="{Binding [0]}" Header="Col1" />
50
-
51
26
  <DataGridTextColumn Binding="{Binding [1]}" Header="Col2" />
52
-
53
27
  <DataGridTextColumn Binding="{Binding [2]}" Header="Col3" />
54
-
55
28
  <DataGridTextColumn Binding="{Binding [3]}" Header="Col4" />-->
56
-
57
29
  </DataGrid.Columns>
58
-
59
30
  </DataGrid>
60
31
 
61
-
62
-
63
32
  <DataGrid
64
-
65
33
  x:Name="DataGrid_CSV2"
66
-
67
34
  Grid.Row="1"
68
-
69
35
  AutoGenerateColumns="False">
70
-
71
36
  <DataGrid.Columns>
72
-
73
37
  <DataGridTextColumn Binding="{Binding [0]}" Header="Col1" />
74
-
75
38
  <DataGridTextColumn Binding="{Binding [1]}" Header="Col2" />
76
-
77
39
  <DataGridTextColumn Binding="{Binding [2]}" Header="Col3" />
78
-
79
40
  <DataGridTextColumn Binding="{Binding [3]}" Header="Col4" />
80
-
81
41
  </DataGrid.Columns>
82
-
83
42
  </DataGrid>
84
-
85
43
  </Grid>
86
-
87
44
  </Window>
88
-
89
45
  ```
90
-
91
- ```C#
46
+ ```cs
92
-
93
47
  using System;
94
-
95
48
  using System.Collections.Generic;
96
-
97
49
  using System.IO;
98
-
99
50
  using System.Text;
100
-
101
51
  using System.Windows;
102
52
 
53
+ namespace Questions241547
54
+ {
55
+ public partial class MainWindow : Window
56
+ {
57
+ public MainWindow()
58
+ {
59
+ InitializeComponent();
60
+ FileRead1(@"test.csv");
61
+ FileRead2(@"test.csv");
62
+ }
63
+ private void FileRead1(string path_read)
64
+ {
65
+ try
66
+ {
67
+ using(var sr = new StreamReader(path_read, Encoding.GetEncoding("shift_jis")))
68
+ {
69
+ List<string> list_param = new List<string>();
70
+ while(!sr.EndOfStream)
71
+ {
72
+ string line = sr.ReadLine();
73
+ string[] csv_array = line.Split(',');
74
+ list_param.Add(csv_array[0]);
75
+ }
103
76
 
104
-
77
+ DataGrid_CSV1.ItemsSource = list_param;
78
+ }
79
+ }
105
- namespace Questions241547
80
+ catch(Exception e)
106
-
107
- {
81
+ {
108
-
109
- public partial class MainWindow : Window
110
-
111
- {
112
-
113
- public MainWindow()
114
-
115
- {
116
-
117
- InitializeComponent();
118
-
119
- FileRead1(@"test.csv");
82
+ MessageBox.Show(e.Message);
120
-
121
- FileRead2(@"test.csv");
83
+ }
122
-
123
84
  }
124
85
 
125
- private void FileRead1(string path_read)
86
+ private void FileRead2(string path_read)
126
-
127
87
  {
128
-
129
88
  try
130
-
131
89
  {
132
-
133
90
  using(var sr = new StreamReader(path_read, Encoding.GetEncoding("shift_jis")))
134
-
135
91
  {
136
-
92
+ //List<string> list_param = new List<string>();
137
- List<string> list_param = new List<string>();
93
+ List<string[]> list_param = new List<string[]>();
138
-
139
94
  while(!sr.EndOfStream)
140
-
141
95
  {
142
-
143
96
  string line = sr.ReadLine();
144
-
145
97
  string[] csv_array = line.Split(',');
146
-
98
+ //list_param.Add(csv_array[0]);
147
- list_param.Add(csv_array[0]);
99
+ list_param.Add(csv_array);
148
-
149
100
  }
150
101
 
151
-
152
-
153
- DataGrid_CSV1.ItemsSource = list_param;
102
+ DataGrid_CSV2.ItemsSource = list_param;
154
-
155
103
  }
156
-
157
104
  }
158
-
159
105
  catch(Exception e)
160
-
161
106
  {
162
-
163
107
  MessageBox.Show(e.Message);
164
-
165
108
  }
166
-
167
109
  }
168
-
169
-
170
-
171
- private void FileRead2(string path_read)
172
-
173
- {
174
-
175
- try
176
-
177
- {
178
-
179
- using(var sr = new StreamReader(path_read, Encoding.GetEncoding("shift_jis")))
180
-
181
- {
182
-
183
- //List<string> list_param = new List<string>();
184
-
185
- List<string[]> list_param = new List<string[]>();
186
-
187
- while(!sr.EndOfStream)
188
-
189
- {
190
-
191
- string line = sr.ReadLine();
192
-
193
- string[] csv_array = line.Split(',');
194
-
195
- //list_param.Add(csv_array[0]);
196
-
197
- list_param.Add(csv_array);
198
-
199
- }
200
-
201
-
202
-
203
- DataGrid_CSV2.ItemsSource = list_param;
204
-
205
- }
206
-
207
- }
208
-
209
- catch(Exception e)
210
-
211
- {
212
-
213
- MessageBox.Show(e.Message);
214
-
215
- }
216
-
217
- }
218
-
219
110
  }
220
-
221
111
  }
222
-
223
112
  ```

2

変更点明示

2020/02/15 13:26

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -38,7 +38,7 @@
38
38
 
39
39
  </Grid.RowDefinitions>
40
40
 
41
-
41
+
42
42
 
43
43
  <DataGrid x:Name="DataGrid_CSV1" AutoGenerateColumns="False">
44
44
 
@@ -46,11 +46,19 @@
46
46
 
47
47
  <DataGridTextColumn Binding="{Binding}" Header="Col1" />
48
48
 
49
+ <!--<DataGridTextColumn Binding="{Binding [0]}" Header="Col1" />
50
+
51
+ <DataGridTextColumn Binding="{Binding [1]}" Header="Col2" />
52
+
53
+ <DataGridTextColumn Binding="{Binding [2]}" Header="Col3" />
54
+
55
+ <DataGridTextColumn Binding="{Binding [3]}" Header="Col4" />-->
56
+
49
57
  </DataGrid.Columns>
50
58
 
51
59
  </DataGrid>
52
60
 
53
-
61
+
54
62
 
55
63
  <DataGrid
56
64
 
@@ -172,6 +180,8 @@
172
180
 
173
181
  {
174
182
 
183
+ //List<string> list_param = new List<string>();
184
+
175
185
  List<string[]> list_param = new List<string[]>();
176
186
 
177
187
  while(!sr.EndOfStream)
@@ -182,6 +192,8 @@
182
192
 
183
193
  string[] csv_array = line.Split(',');
184
194
 
195
+ //list_param.Add(csv_array[0]);
196
+
185
197
  list_param.Add(csv_array);
186
198
 
187
199
  }

1

箇条書き

2020/02/15 13:26

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -4,9 +4,11 @@
4
4
 
5
5
 
6
6
 
7
- xamlを変える(回答コードのDataGrid_CSV1・FileRead1)
7
+ * xamlを変える(回答コードのDataGrid_CSV1・FileRead1)
8
-
8
+
9
- いっそ段階を踏まず全部出す(回答コードのDataGrid_CSV2・FileRead2)
9
+ * 段階を踏まず全部出す(回答コードのDataGrid_CSV2・FileRead2)
10
+
11
+
10
12
 
11
13
  かでしょうか。
12
14