将DatagridView Selected值传递给打开的表单而不打开新表单

时间:2015-12-03 05:04:09

标签: vb.net datagridview

您好我有一个名为service_reservation的表单。当我单击其中的一个按钮时,我会得到一个带有datagridview的表单,而不会关闭service_reservation表单。我想要的是将选定的值从数据网格视图传递到打开的Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim i As Integer i = DataGridView1.CurrentRow.Index If i >= 0 Then Service_Reservation.txtBoxSerID.Text = DataGridView1.Item(0, i).Value Service_Reservation.Show() Me.Close() Else MessageBox.Show("Empty Row Clicked") End If End Sub 表单,而无需打开新表单。

service_reservation

但是上面的代码显示了新的{{1}}表单。请帮忙

1 个答案:

答案 0 :(得分:-1)

Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e As 
 System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim i As Integer
    i = DataGridView1.CurrentRow.Index
    If i >= 0 Then
        Service_Reservation.Show()  
        Service_Reservation.txtBoxSerID.Text = DataGridView1.Item(0, i).Value
        Me.Close()
    Else
        MessageBox.Show("Empty Row Clicked")
    End If
End Sub