teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

修正

2020/08/28 08:30

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,9 +1,9 @@
1
1
  csvファイルを取り込んでdatagridviewに表示した表のヘッダーの順番を入れ替え行のデータも一緒に変えること。表示する行データの選択。選択したヘッダの行データ1列削除することは可能なのでしょうか?
2
2
  ``````ここに言語を入力
3
3
 
4
- private void Read(string path)
4
+ private void Read(string filepath)
5
5
  {
6
- DataTable data = new DataTable();
6
+ DataTable dataTable = new DataTable();
7
7
  string[] lines = File.ReadAllLines(filepath,Encoding.GetEncoding("Shift_JIS"));
8
8
  if(lines.Length>0)
9
9
  {

3

修正

2020/08/28 08:30

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -32,6 +32,12 @@
32
32
  }
33
33
  }
34
34
  ```
35
-
35
+ サンプルとして
36
-
36
+ コード,名前,生息地,番号,メールアドレス
37
+ 0001,佐藤,神奈川県,0000-00-0000,nakayama@aaa.com
37
- [サンプルCSVです](https://knowledge-ja.domo.com/Training/Self-Service_Training/Onboarding_Resources/Fun_Sample_Datasets)
38
+ 0002,土田,新潟県,0120-00-1245,sdjnaidm@aaa.com
39
+ 0003,中山,富山県,0786-00-0000,fhsuw@aaa.com
40
+ 0004,田中,愛知県,0516-00-2652,aaaaa@aaa.com
41
+ 0005,山田,石川県,0585-58-5482,yamada@aaaa.com
42
+ 0006,鈴木,山梨県,0555-55-5555,suzuki@aaaa.com
43
+ 0007,大田,福岡県,5584-58-2541,oota@saaa.com

2

修正

2020/08/28 07:52

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -31,4 +31,7 @@
31
31
  dataGridView1.DataSource = dataTable;
32
32
  }
33
33
  }
34
- ```
34
+ ```
35
+
36
+
37
+ [サンプルCSVです](https://knowledge-ja.domo.com/Training/Self-Service_Training/Onboarding_Resources/Fun_Sample_Datasets)

1

code記入

2020/08/28 07:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,1 +1,34 @@
1
- csvファイルを取り込んでdatagridviewに表示した表のヘッダーの順番を入れ替え行のデータも一緒に変えること。表示する行データの選択。選択したヘッダの行データ1列削除することは可能なのでしょうか?
1
+ csvファイルを取り込んでdatagridviewに表示した表のヘッダーの順番を入れ替え行のデータも一緒に変えること。表示する行データの選択。選択したヘッダの行データ1列削除することは可能なのでしょうか?
2
+ ``````ここに言語を入力
3
+
4
+ private void Read(string path)
5
+ {
6
+ DataTable data = new DataTable();
7
+ string[] lines = File.ReadAllLines(filepath,Encoding.GetEncoding("Shift_JIS"));
8
+ if(lines.Length>0)
9
+ {
10
+ string firstline = lines[0];
11
+ string[] strHeader = firstline.Split(',');
12
+ foreach(string strWorld in strHeader)
13
+ {
14
+ dataGridView1.Columns.Clear();
15
+ dataTable.Columns.Add(new DataColumn(strWorld));
16
+ }
17
+ for(int row=1;row<lines.Length;row++)
18
+ {
19
+ string[] word = lines[row].Split(',');
20
+ DataRow dataRow = dataTable.NewRow();
21
+ int columindex = 0;
22
+ foreach(string strWorld in strHeader)
23
+ {
24
+ dataRow[strWorld] = word[columindex++];
25
+ }
26
+ dataTable.Rows.Add(dataRow);
27
+ }
28
+ }
29
+ if(dataTable.Rows.Count>0)
30
+ {
31
+ dataGridView1.DataSource = dataTable;
32
+ }
33
+ }
34
+ ```