how to receive values continuously from one form to another in VB.NET?

0

I am trying to create a (a) link between 2 forms, well the main one is of type MDI (first form) so in the second form I have a DataGridView and when I select a row, I created a variable that takes its value and immediately with a button I show the variable in the form 3, well I leave some reference images. in the FRM_Nuevo (2)

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Try
        Dim i As Integer
        Dim selecionar_columna As DataGridViewRow
        i = e.RowIndex
        selecionar_columna = DataGridView1.Rows(i)
        a = selecionar_columna.Cells(0).Value     'variable enlace (a)

    Catch ex As Exception
        'no pasa nada
    End Try
End Sub

In the Frm_Editar (3)

Public Class Frm_Editar
 Public a As Integer
 Private Sub Frm_Editar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Label.Text = a 'esto funciona solo al iniciar el formulario
    End Sub
End Class

I would like you to click on the DataGridView1 and with the open form 3, change the text of the Label, can you do it ?, I need your help and if there is something you have not understood about my question, do not hesitate to let me know .

    
asked by royer 25.11.2018 в 05:19
source

1 answer

0

Try the following:

In your event DataGridView1_CellClick write this:

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    Dim i As Integer

    If Not DataGridView1.CurrentRow Is Nothing Then
        i = DataGridView1.CurrentRow.Index

        Frm_Editar.Label1.Text = DataGridView1.Item(0, i).Value
    End If
End Sub

I hope it serves you.

    
answered by 26.11.2018 / 04:12
source