Pass value from one combobox to another label of another form in visual basic

1

Hello good afternoon Family. a query how can I pass value from a combobox to another label of another form? I'm doing this code in my first form:

 Private Sub DtgImportar_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DtgImportar.CellDoubleClick
    Try
        ivIncidencia = 0
        ivIncidencia = DtgImportar.Rows(e.RowIndex).Cells(1).Value()
        Me.Close()

        FrmAtencion.Show()
        CboUsuario.Text = FrmAtencion.lblusuarioanterior.Text

    Catch ex As Exception
        MsgBox(Err.Description, MsgBoxStyle.Critical, "..:: Aviso del Sistema ::..")
        Exit Try
    End Try
End Sub

but when I go to my other form that label is empty

    
asked by PieroDev 11.05.2017 в 22:46
source

2 answers

1

If what you want to do is put the value of the combo CboUsuario in the previous lblusuario label you should follow this order:

        FrmAtencion.lblusuarioanterior.Text = CboUsuario.Text;
        FrmAtencion.Show();

I would recommend using public methods to do this and give more transparency to the code something like this:

FrmAtencion atencion = new FrmAtencion();
atencion.SetearLabel(CboUsuario.Text);
atencion.Show();

And inside the form FrmAntencion put:

public void SetearLabel(string texto){
  lblusuarioanterior.Text = texto;
}
    
answered by 11.05.2017 в 22:56
0

I usually do it in the following way:

In the form you want to call (I think it's FrmAntencion) I would say the following:

Public Sub New(ByVal Usuario as string)
     Me.lblusuarioanterior.Text = Usuario
End Sub

And in the form from which you call it, you would put:

Dim f as New FrmAtencion(CboUsuario.Text)
f.Show()
Me.Close()
    
answered by 24.05.2017 в 16:18