6 列で行数が不明なフォームに datagridview があります。ユーザーはこのデータグリッドビューに値を入力しています。datagridview のエントリに基づいて請求書を作成したいと思います。別のフォームでこの請求書を作成しています。残念ながら、セル内の値は私が持っているコードでは表示されません。これは Invoice クラスにあるコードです。
Dim lbl(5) As Label
For Each row As DataGridViewRow In Main.DataGridView1.Rows
If Not row.IsNewRow Then
Dim x As Integer = 0
For Each col As DataGridViewColumn In Main.DataGridView1.Columns
i = row.Index
j = col.Index
With lbl(x)
.AutoSize = True
.BackColor = System.Drawing.SystemColors.Control
.Font = New Font(lbl(x).Font.FontFamily, 8.45, FontStyle.Regular)
.ForeColor = System.Drawing.SystemColors.ControlText
.Location = New System.Drawing.Point(i * 111 + 6, (i + 1) * 24 + 16)
.Text = Main.DataGridView1.Rows(i).Cells(j).Value
End With
MsgBox(lbl(x).Text)
GroupBoxInvoiceInvoice.Controls.Add(lbl(x))
x += 1
Next
End If
Next
どんな助けでも大歓迎です!
これが新しいコードブロックです。
Dim Label1, Label2, Label3, Label4, Label5, Label6 As New Label
Dim lbl() As Control = {Label1, Label2, Label3, Label4, Label5, Label6}
Dim val() As String = {"Date", "Category", "Description", "Units", "Rate", "Amount"}
For Each row As DataGridViewRow In Main.DataGridView1.Rows
If Not row.IsNewRow And i < Main.DataGridView1.Rows.Count Then
Dim x As Integer = 0
For Each col As DataGridViewColumn In Main.DataGridView1.Columns
i = row.Index
j = col.Index
With lbl(x)
.AutoSize = True
.BackColor = System.Drawing.SystemColors.Control
.Font = New Font(lbl(x).Font.FontFamily, 8.45, FontStyle.Regular)
.ForeColor = System.Drawing.SystemColors.ControlText
.Location = New System.Drawing.Point(j * 111 + 6, (i + 1) * 24 + 16)
.Text = Main.DataGridView1.Rows(i).Cells(j).Value
End With
GroupBoxInvoiceInvoice.Controls.Add(lbl(x))
x += 1
j += 1
Next
i += 1
j = 0
x = 0
End If
Next
ありがとう、プルトニクス!! あなたの助けは素晴らしいものであり、非常に感謝しています! また、あなたは多くの忍耐を示しました!以下に示したものに基づいて、私のために働いたコードの最後の部分を次に示します。再度、感謝します!!
i = 0
For Each row As DataGridViewRow In Main.DataGridView1.Rows
If Not row.IsNewRow Then
For c As Integer = 0 To row.Cells.Count - 3
Dim lbl As New Label
With lbl
.AutoSize = True
.BackColor = System.Drawing.SystemColors.Control
.Font = New Font(lbl.Font.FontFamily, 8.45, FontStyle.Regular)
.ForeColor = System.Drawing.SystemColors.ControlText
.Location = New System.Drawing.Point(c * 111 + 6, (i + 1) * 24 + 16)
.Text = row.Cells(c).Value.ToString
End With
GroupBoxInvoiceInvoice.Controls.Add(lbl)
Console.WriteLine("label {0}", row.Cells(c).Value.ToString)
Next
End If
i += 1
Next