Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a value from one form to another

Status
Not open for further replies.

jpinto

Technical User
Dec 12, 2003
75
0
0
PT
Hello,

I've a form that when the user clicks on a button opens a new form with a treeview with data for the user to select.
After the user selects the data and clicks OK button I want to pass the value of the row selected to a field from the first form.

I'm using a variable to put the value of the selected node:

Code:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
     OcorrenciaSelected = trvOcorrencias.SelectedNode.Text
     Me.Close()
End Sub

Wich event should I use on the firts form to do something like:

Code:
txtDescricao.Text = OcorrenciaSelected

I've tryed to put on the class above a command to do:

Code:
frmInserirOcorrencia.txtDescricao.Text = OcorrenciaSelected
but it's not working also.

Thanks for your help,

João Pinto
 
place

frmInserirOcorrencia.txtDescricao.Text = OcorrenciaSelected

in the OK_button_click subroutine right after

the "txtDescricao.Text = OcorrenciaSelected" statement
 
Hello bobmori,

The first think that I've tryed was what you say:

Code:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        OcorrenciaSelected = trvOcorrencias.SelectedNode.Text
        'frmInserirOcorrencia.txtDescricao.Text = OcorrenciaSelected
        Me.Close()
    End Sub

this is not working also. I don't know why!

I've looked on the FAQ but I didn't manage to workaround the problem with the solutions presented there.

Does annyone knows how I can solve this problem?

Thanks,

João Pinto
 
Does annyone knows how to solve this problem, please? Thanks.

João Pinto
 
Yes, follow the link on the top of this page that says "FAQs". Then scroll down until you see a FAQ with the title "a Thousand ways to transfer data between forms". Or just click here: faq796-5773

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I've looked at the FAQ and the one that you've mentioned. None have the solution to my problem. My problem is:

what event should I call on form1 to retrieve the value that I've selected on form2 and assign it to a field on form1?

Example:

On form1 I click a button that opens form2 that has a treeview with options for me to select;
after I select an option from the treeview on form2 I assign it to a variable (public) and close form2;
I then return to form1 (it wasn't closed during the process on form2) and want to assign the value of the public variable to txtDescricao.text field.
What event should I use to put txtDescricao.text=ValueSelected?

Thanks,

João Pinto
 
I've allready seen the FAQ mentioned.

It doesn't solve my problem. The main problem is in what event of the primary form should I put the txtDescricao.text=ValueSelected instruction!

Thanks,

João Pinto
 
Answer: You shouldn't.

That FAQ is not written to "fix your problem". It was written to give you a rough idea of how to use a custom form as a dialogue to acheive the desired results you appear to be describing.

Use the second form as a dialogue. Call a method on the 2nd form from the 1st form that will instantiate the 2nd form and wait for it to close before returning the selected value. When that value is returned, the calling method will continue.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top