Question How do I parse value from one form to another?

black zero

Well-known member
Joined
Jan 15, 2009
Messages
53
Programming Experience
Beginner
Here's the scenario:

I have a table 'userdata' that contains 'username' and 'id'. I have a form called kelancaran1 and kelancaran2.

The first form has a link to kelancaran2, kelancaran2's form load event will query all value from userdata to datagrid and display it for a user to pick. On a double click event on that datagrid, the value username and id would be passed down to kelancaran1 form, and displayed on textboxes, username.text and id.text respectively.

Could you please tell me the easiest way to do this? I am totally clueless...
 
The second form should expose the data via public properties. When the dialogue is dismissed, the first form can read those properties just like you read any other properties.
 
The second form should expose the data via public properties. When the dialogue is dismissed, the first form can read those properties just like you read any other properties.

Alright, makes sense for me. Duh... I'm a newbie, mind you. :(

And oh, which event should I use on the first form? textbox doubleclick? I want to do it without user intervention, just a doubleclick they do on the second form to pick the id.
 
If the double-click is occurring on the secpond form then you aren't going to be handling any events of, or on, the first form. You'd handle the appropriate event on the second form, make the data available via your properties and then set the DialogResult to OK. What action are you expecting to close this form? The user double-clicking on a row in the grid? Then you have to handle the appropriate event of that grid.

I'm assuming that you've displayed this second form using ShowDialog. If so then the first form will block at that point until the second from is dismissed. At that point you just test the value that ShowDialog returned. If it's OK then you know the user made a selection and you can safely get the data from the properties of the second form.
 
Here's my code to display the second form (this code is located on form 1, on label click event)

VB.NET:
[B][COLOR="Red"]frm_cr_kpl.ShowDialog()[/COLOR][/B]
        If Module1.kd_kpl <> "" Then
            da = New SqlDataAdapter("Select * from Kapal where ID_Kapal='" & Module1.kd_kpl & "'", con)
            da.Fill(ds, "cr_kpl")
            da.Dispose()

            txtIdKapal.Text = Trim(ds.Tables("cr_kpl").Rows(0).Item(0))
            TxtNmKapal.Text = Trim(ds.Tables("cr_kpl").Rows(0).Item(1))

            ds.Tables("cr_kpl").Clear()
        End If

And after user click that label, the frm_cr_kpl will appear.

There's datagrid on that second form. The data is loaded automatically on form load event to that datagrid. User will need to double click on that datagrid to choose the correct record he/she wants. Here's the code for double click event:

VB.NET:
        If ds.Tables("kpl").Rows.Count - 1 <> -1 Then
            kd_kpl = DgCrKPL.Item(DgCrKPL.CurrentRowIndex, 0)
            Me.Close()
        End If

What I'd like to ask is:

On that red-font line,

The form1 should stop functioning on that event, rite? And proceed after the dialogbox is closed. I've checked everything and this should be working, but in this case.... no. Anything wrong with my code?
 
Back
Top