質問編集履歴
5
追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
### 教えていただきたいこと
|
6
6
|
そこで今度は逆に読み込みボタンを押してローカルに保存してあるcsvファイルを選択し、datagridviewに表示させる機能を付けたいのですが、どこのサイトを見てもやり方を見つけることが出来ませんでした。具体的なコードなどを教えていただけると幸いです。
|
7
7
|
|
8
|
+
追記
|
9
|
+
http://bbs.wankuma.com/index.cgi?mode=al2&namber=90559
|
10
|
+
時間がなかったため、こちらのサイトでも同時並行で同じアプリの質問をしていました。
|
8
11
|
|
9
12
|
|
10
13
|
```
|
4
修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,9 +5,9 @@
|
|
5
5
|
### 教えていただきたいこと
|
6
6
|
そこで今度は逆に読み込みボタンを押してローカルに保存してあるcsvファイルを選択し、datagridviewに表示させる機能を付けたいのですが、どこのサイトを見てもやり方を見つけることが出来ませんでした。具体的なコードなどを教えていただけると幸いです。
|
7
7
|
|
8
|
-
```Form1.vb
|
9
8
|
|
10
9
|
|
10
|
+
```
|
11
11
|
Public Class Form1
|
12
12
|
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
|
13
13
|
Me.Close()
|
@@ -89,4 +89,5 @@
|
|
89
89
|
FileName = sfd.FileName
|
90
90
|
End Using
|
91
91
|
CsvFileSave(FileName)
|
92
|
-
|
92
|
+
End Sub
|
93
|
+
```
|
3
修正しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,106 +5,88 @@
|
|
5
5
|
### 教えていただきたいこと
|
6
6
|
そこで今度は逆に読み込みボタンを押してローカルに保存してあるcsvファイルを選択し、datagridviewに表示させる機能を付けたいのですが、どこのサイトを見てもやり方を見つけることが出来ませんでした。具体的なコードなどを教えていただけると幸いです。
|
7
7
|
|
8
|
-
Form1.vb
|
8
|
+
```Form1.vb
|
9
9
|
|
10
|
+
|
10
11
|
Public Class Form1
|
11
|
-
|
12
|
+
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
|
12
|
-
|
13
|
+
Me.Close()
|
13
|
-
|
14
|
+
End Sub
|
15
|
+
Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click
|
14
16
|
|
15
|
-
|
17
|
+
Dim Height As Double = txtHeight.Text
|
18
|
+
Dim Weight As Double = txtWeight.Text
|
19
|
+
Dim Name As String = txtName.Text
|
16
20
|
|
21
|
+
Dim BMI As Double
|
17
|
-
|
22
|
+
If Height > 0 AndAlso Weight > 0 Then
|
23
|
+
lblerror.Text = "" BMI = Weight / ((Height / 100) * (Height / 100))
|
24
|
+
txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
|
18
25
|
|
19
|
-
```Dim Weight As Double = txtWeight.Text```
|
20
|
-
|
21
|
-
```Dim Name As String = txtName.Text```
|
22
|
-
|
23
|
-
```Dim BMI As Double```
|
24
|
-
|
25
|
-
```If Height > 0 AndAlso Weight > 0 Then
|
26
|
-
lblerror.Text = ""```
|
27
|
-
```BMI = Weight / ((Height / 100) * (Height / 100))```
|
28
|
-
|
29
|
-
```txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
|
30
|
-
|
31
26
|
'肥満度判定
|
32
|
-
|
27
|
+
If txtBMI.Text >= 25 Then
|
33
|
-
```lblHimando.Text = "肥満"```
|
34
|
-
|
28
|
+
lblHimando.Text = "肥満" ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
|
35
|
-
lblHimando.Text = "普通"
|
29
|
+
lblHimando.Text = "普通"
|
36
|
-
|
30
|
+
ElseIf txtBMI.Text < 18.5 Then
|
37
|
-
lblHimando.Text = "痩せ"
|
31
|
+
lblHimando.Text = "痩せ"
|
38
|
-
|
32
|
+
End If
|
39
33
|
|
40
34
|
'肥満度によって文字の色を変更
|
41
|
-
|
35
|
+
If lblHimando.Text = "肥満" Then
|
42
|
-
lblHimando.ForeColor = Color.Red```
|
43
|
-
|
36
|
+
lblHimando.ForeColor = Color.Red ElseIf lblHimando.Text = "痩せ" Then
|
44
|
-
lblHimando.ForeColor = Color.Blue
|
37
|
+
lblHimando.ForeColor = Color.Blue
|
45
|
-
|
46
|
-
|
38
|
+
End If
|
47
|
-
|
48
39
|
'0以下が入力された時にエラーメッセージを表示
|
49
|
-
```Else```
|
50
|
-
|
40
|
+
Else lblerror.Text = "正しい値を入力してください"
|
51
|
-
lblHimando.Text = ""
|
41
|
+
lblHimando.Text = ""
|
52
|
-
|
42
|
+
End If
|
43
|
+
End Sub
|
44
|
+
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
|
53
45
|
|
54
|
-
|
46
|
+
End Sub
|
47
|
+
Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click
|
48
|
+
If txtBMI.Text = "" Then
|
49
|
+
lblerror.Text = "計算してください"
|
50
|
+
Else
|
51
|
+
Dim idx As Integer = DataGridView1.Rows.Add() DataGridView1.Rows(idx).Cells(0).Value = idx
|
52
|
+
DataGridView1.Rows(idx).Cells(1).Value = txtName.Text
|
53
|
+
DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text
|
54
|
+
DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text
|
55
|
+
DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text
|
55
56
|
|
56
|
-
```Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick```
|
57
57
|
|
58
|
-
```End Sub```
|
59
58
|
|
60
|
-
```Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click```
|
61
59
|
|
60
|
+
End If
|
62
|
-
|
61
|
+
End Sub
|
63
|
-
lblerror.Text = "計算してください"```
|
64
62
|
|
65
|
-
|
63
|
+
Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
|
66
64
|
|
67
|
-
```Dim idx As Integer = DataGridView1.Rows.Add()```
|
68
|
-
|
65
|
+
End Sub
|
69
|
-
```DataGridView1.Rows(idx).Cells(1).Value = txtName.Text```
|
70
|
-
```DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text```
|
71
|
-
```DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text```
|
72
|
-
```DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text```
|
73
66
|
|
67
|
+
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
74
68
|
|
69
|
+
End Sub
|
70
|
+
Private Sub Button2_Click(ByVal sender As System.Object,
|
71
|
+
ByVal e As System.EventArgs) Handles Button2.Click
|
75
72
|
|
73
|
+
CsvFileSave("BMIデータ.csv")
|
74
|
+
End Sub
|
75
|
+
Dim FileName As String
|
76
|
+
Public Property OpenFileDialog1 As Object
|
76
77
|
|
77
|
-
```End If```
|
78
|
-
|
78
|
+
Private Sub CsvFileSave(ByVal SaveFileName As String)
|
79
79
|
|
80
|
-
```Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged```
|
81
|
-
|
82
|
-
```End Sub```
|
83
|
-
|
84
|
-
```Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load```
|
85
|
-
|
86
|
-
```End Sub```
|
87
|
-
```Private Sub Button2_Click(ByVal sender As System.Object,
|
88
|
-
ByVal e As System.EventArgs) Handles Button2.Click```
|
89
|
-
|
90
|
-
```CsvFileSave("BMIデータ.csv")```
|
91
|
-
```End Sub```
|
92
|
-
|
93
|
-
```Dim FileName As String```
|
94
|
-
```Public Property OpenFileDialog1 As Object```
|
95
|
-
|
96
|
-
```Private Sub CsvFileSave(ByVal SaveFileName As String)```
|
97
|
-
|
98
80
|
' 「名前を付けて保存」ダイアログを使う方法
|
99
|
-
|
81
|
+
Using sfd As New SaveFileDialog
|
100
|
-
|
82
|
+
sfd.FileName = "BMIデータ.csv"
|
101
|
-
|
83
|
+
sfd.Filter = "CSV(*.csv)|*.csv"
|
102
|
-
|
84
|
+
sfd.CheckPathExists = True
|
103
|
-
|
85
|
+
sfd.OverwritePrompt = True
|
104
|
-
|
86
|
+
If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
|
105
|
-
Exit Sub
|
87
|
+
Exit Sub
|
106
|
-
|
88
|
+
End If
|
107
|
-
|
89
|
+
FileName = sfd.FileName
|
108
|
-
|
90
|
+
End Using
|
109
|
-
|
91
|
+
CsvFileSave(FileName)
|
110
|
-
```End Sub
|
92
|
+
```End Sub
|
2
```で囲いました
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,103 +8,103 @@
|
|
8
8
|
Form1.vb
|
9
9
|
|
10
10
|
Public Class Form1
|
11
|
-
|
11
|
+
``` Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click```
|
12
|
-
|
12
|
+
```Me.Close()```
|
13
|
-
|
13
|
+
```End Sub```
|
14
14
|
|
15
|
-
Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click
|
15
|
+
```Private Sub btnBMI_Click(sender As Object, e As EventArgs) Handles btnBMI.Click```
|
16
16
|
|
17
|
-
|
17
|
+
```Dim Height As Double = txtHeight.Text```
|
18
18
|
|
19
|
-
Dim Weight As Double = txtWeight.Text
|
19
|
+
```Dim Weight As Double = txtWeight.Text```
|
20
20
|
|
21
|
-
Dim Name As String = txtName.Text
|
21
|
+
```Dim Name As String = txtName.Text```
|
22
22
|
|
23
|
-
Dim BMI As Double
|
23
|
+
```Dim BMI As Double```
|
24
24
|
|
25
|
-
If Height > 0 AndAlso Weight > 0 Then
|
25
|
+
```If Height > 0 AndAlso Weight > 0 Then
|
26
|
-
lblerror.Text = ""
|
26
|
+
lblerror.Text = ""```
|
27
|
-
BMI = Weight / ((Height / 100) * (Height / 100))
|
27
|
+
```BMI = Weight / ((Height / 100) * (Height / 100))```
|
28
28
|
|
29
|
-
txtBMI.Text = BMI.ToString("0.0") '有効数字以下は四捨五入される
|
29
|
+
```txtBMI.Text = BMI.ToString("0.0")``` '有効数字以下は四捨五入される
|
30
30
|
|
31
31
|
'肥満度判定
|
32
|
-
If txtBMI.Text >= 25 Then
|
32
|
+
```If txtBMI.Text >= 25 Then```
|
33
|
-
lblHimando.Text = "肥満"
|
33
|
+
```lblHimando.Text = "肥満"```
|
34
|
-
ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
|
34
|
+
```ElseIf txtBMI.Text < 25 AndAlso txtBMI.Text >= 18.5 Then
|
35
|
-
lblHimando.Text = "普通"
|
35
|
+
lblHimando.Text = "普通"```
|
36
|
-
ElseIf txtBMI.Text < 18.5 Then
|
36
|
+
```ElseIf txtBMI.Text < 18.5 Then
|
37
|
-
lblHimando.Text = "痩せ"
|
37
|
+
lblHimando.Text = "痩せ"```
|
38
|
-
End If
|
38
|
+
```End If
|
39
39
|
|
40
40
|
'肥満度によって文字の色を変更
|
41
|
-
If lblHimando.Text = "肥満" Then
|
41
|
+
```If lblHimando.Text = "肥満" Then
|
42
|
-
lblHimando.ForeColor = Color.Red
|
42
|
+
lblHimando.ForeColor = Color.Red```
|
43
|
-
ElseIf lblHimando.Text = "痩せ" Then
|
43
|
+
```ElseIf lblHimando.Text = "痩せ" Then
|
44
|
-
lblHimando.ForeColor = Color.Blue
|
44
|
+
lblHimando.ForeColor = Color.Blue```
|
45
45
|
|
46
|
-
End If
|
46
|
+
```End If```
|
47
47
|
|
48
48
|
'0以下が入力された時にエラーメッセージを表示
|
49
|
-
Else
|
49
|
+
```Else```
|
50
|
-
lblerror.Text = "正しい値を入力してください"
|
50
|
+
```lblerror.Text = "正しい値を入力してください"
|
51
|
-
lblHimando.Text = ""
|
51
|
+
lblHimando.Text = ""```
|
52
|
-
End If
|
52
|
+
```End If```
|
53
53
|
|
54
|
-
End Sub
|
54
|
+
```End Sub```
|
55
55
|
|
56
|
-
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
|
56
|
+
```Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick```
|
57
57
|
|
58
|
-
End Sub
|
58
|
+
```End Sub```
|
59
59
|
|
60
|
-
Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click
|
60
|
+
```Private Sub btnTouroku_Click(sender As Object, e As EventArgs) Handles btnTouroku.Click```
|
61
61
|
|
62
|
-
If txtBMI.Text = "" Then
|
62
|
+
```If txtBMI.Text = "" Then
|
63
|
-
lblerror.Text = "計算してください"
|
63
|
+
lblerror.Text = "計算してください"```
|
64
64
|
|
65
|
-
Else
|
65
|
+
```Else```
|
66
66
|
|
67
|
-
Dim idx As Integer = DataGridView1.Rows.Add()
|
67
|
+
```Dim idx As Integer = DataGridView1.Rows.Add()```
|
68
|
-
DataGridView1.Rows(idx).Cells(0).Value = idx
|
68
|
+
```DataGridView1.Rows(idx).Cells(0).Value = idx```
|
69
|
-
DataGridView1.Rows(idx).Cells(1).Value = txtName.Text
|
69
|
+
```DataGridView1.Rows(idx).Cells(1).Value = txtName.Text```
|
70
|
-
DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text
|
70
|
+
```DataGridView1.Rows(idx).Cells(2).Value = txtHeight.Text```
|
71
|
-
DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text
|
71
|
+
```DataGridView1.Rows(idx).Cells(3).Value = txtWeight.Text```
|
72
|
-
DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text
|
72
|
+
```DataGridView1.Rows(idx).Cells(4).Value = txtBMI.Text```
|
73
73
|
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
-
End If
|
77
|
+
```End If```
|
78
|
-
End Sub
|
78
|
+
```End Sub```
|
79
79
|
|
80
|
-
Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged
|
80
|
+
```Private Sub txtName_TextChanged(sender As Object, e As EventArgs) Handles txtName.TextChanged```
|
81
81
|
|
82
|
-
End Sub
|
82
|
+
```End Sub```
|
83
83
|
|
84
|
-
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
84
|
+
```Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load```
|
85
85
|
|
86
|
-
End Sub
|
86
|
+
```End Sub```
|
87
|
-
Private Sub Button2_Click(ByVal sender As System.Object,
|
87
|
+
```Private Sub Button2_Click(ByVal sender As System.Object,
|
88
|
-
ByVal e As System.EventArgs) Handles Button2.Click
|
88
|
+
ByVal e As System.EventArgs) Handles Button2.Click```
|
89
89
|
|
90
|
-
CsvFileSave("BMIデータ.csv")
|
90
|
+
```CsvFileSave("BMIデータ.csv")```
|
91
|
-
End Sub
|
91
|
+
```End Sub```
|
92
92
|
|
93
|
-
Dim FileName As String
|
93
|
+
```Dim FileName As String```
|
94
|
-
Public Property OpenFileDialog1 As Object
|
94
|
+
```Public Property OpenFileDialog1 As Object```
|
95
95
|
|
96
|
-
Private Sub CsvFileSave(ByVal SaveFileName As String)
|
96
|
+
```Private Sub CsvFileSave(ByVal SaveFileName As String)```
|
97
97
|
|
98
98
|
' 「名前を付けて保存」ダイアログを使う方法
|
99
|
-
Using sfd As New SaveFileDialog
|
99
|
+
```Using sfd As New SaveFileDialog```
|
100
|
-
sfd.FileName = "BMIデータ.csv"
|
100
|
+
```sfd.FileName = "BMIデータ.csv"```
|
101
|
-
sfd.Filter = "CSV(*.csv)|*.csv"
|
101
|
+
```sfd.Filter = "CSV(*.csv)|*.csv"```
|
102
|
-
sfd.CheckPathExists = True
|
102
|
+
```sfd.CheckPathExists = True```
|
103
|
-
sfd.OverwritePrompt = True
|
103
|
+
```sfd.OverwritePrompt = True```
|
104
|
-
If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
|
104
|
+
```If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
|
105
|
-
Exit Sub
|
105
|
+
Exit Sub```
|
106
|
-
End If
|
106
|
+
```End If```
|
107
|
-
FileName = sfd.FileName
|
107
|
+
```FileName = sfd.FileName```
|
108
|
-
End Using
|
108
|
+
```End Using```
|
109
|
-
CsvFileSave(FileName)
|
109
|
+
```CsvFileSave(FileName)```
|
110
|
-
End Sub
|
110
|
+
```End Sub```
|
1
特になし
title
CHANGED
File without changes
|
body
CHANGED
@@ -107,9 +107,4 @@
|
|
107
107
|
FileName = sfd.FileName
|
108
108
|
End Using
|
109
109
|
CsvFileSave(FileName)
|
110
|
-
End Sub
|
110
|
+
End Sub
|
111
|
-
### 試したこと
|
112
|
-
|
113
|
-
ここに問題に対して試したことを記載してください。
|
114
|
-
|
115
|
-
### 補足情報(FW/ツールのバージョンなど)
|