关闭form1时,如何将form1.DataGridView1中的值传递给form2.Label1

时间:2018-03-24 11:21:08

标签: vb.net

我正在创建一个函数来从DataGridView获取值。

Private Function ItemaDataTransfer()
    Try
        Dim Purfrm As New Entr_PurchaseForm
        Dim i As Integer
        i = FindItemDataGridView.CurrentRow.Index
        If i > 0 Then
            If Not String.IsNullOrEmpty(FindItemDataGridView.Item(0, i).Value.ToString) Then

                Purfrm.ItemIDLabel.Text = FindItemDataGridView.Item(0, i).Value.ToString

            Else
                Purfrm.ItemIDLabel.Text = 0

            End If
        End If

    Catch ex As ApplicationException
        MessageBox.Show("Error" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Function

这是我的表格:

1

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助。如果确实如此,请通过答案左侧的复选标记接受我的回答。

Private Sub ItemaDataTransfer()
        Try
            Dim i As Integer = FindItemDataGridView.CurrentRow.Index
            If i > 0 Then
                If Not String.IsNullOrEmpty(FindItemDataGridView.Item(0, i).Value.ToString) Then
                    Entr_PurchaseForm.ItemIDLabel.Text = FindItemDataGridView.Item(0, i).Value.ToString
                Else
                    Entr_PurchaseForm.ItemIDLabel.Text = "0"
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Error" & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub