Need help setting a value to a textbox in another form

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Greetings Everyone,

I'm doing an application for a school to help them keep track of student attendance and because I'm rather new to VB 2008 .NET I'm sure I'm missing something simple.

Please see the screen shot and attached sample application showing the problem I am having.

The screen shot shows 3 open forms. I'm not able to get the value from the 3rd open form into the Student ID textbox of the 2nd form even though my messagebox shows a value is really in there.

The attached application has 3 forms similar to the production application I'm writing which also includes 3 forms. Could you look at the application and tell me what we are missing to get the textbox data in the 2nd form to show up?

Any help will be greatly appreciated.

Thanks.

Truly,
Emad

isgl1.jpg
 

Attachments

  • ChangingTextInParentFormFromChildForm.zip
    18.8 KB · Views: 10
Last edited by a moderator:
From the DataGridView in form one (Assume this is DG1 on Form1 and that the Column is called Student_ID and is an integer)

VB.NET:
Addhandler DG1.DoubleClick, Addressof MyDGResults

Assume that the receiving form is Form2 and the textbox has the name TB1

VB.NET:
Private Sub MyDGResults(byval sender as Object, byval e as EventArgs)
Dim vID as integer = DG1.SelectedRows(0).Cells("Student_ID").Value

'If the TextBox control is dynamic, find it 
Dim vObj() as Object = Form2.Controls.Find("TB1", True)
Dim vTB as TextBox = vObj(0)
vTB.Text = vID
 
Hi gchq,

Thanks for the reply.

I'm trying a event handler for the first time using your code but am confused about how to proceed because VB wants the use of the "New" keyword when running the application.

Can you tell me if I placed the code in the correct places?

Please see the attached screen shot.

Truly,
Emad
 

Attachments

  • using the handler.jpg
    using the handler.jpg
    389.3 KB · Views: 16
Looks like you have added the handler before you have defined the DataGridView!

VB.NET:
Dim DG1 as new DataGridView
With DG1
.AllowUserToAddRows = False
.Dock = DockStyle.Fill
End With
AddHandler DG1.DoubleClick AddressOf YourEvent

Form1.Controls.Add(DG1)

If the DataGridView control is not dynamic (you used the drag and drop in design) then, with the control selected, click the events tab in properties and double click the DoubleClick event - that will write the event sub for you - just enter the code into this. I never use designer myself!
 
Hi

Almost there but nothing shows up on the form even though the messagebox shows vTB.Text having an actual value from the doubleclick.

Here's what the doubleclick event from the designer looks like now:
VB.NET:
    Private Sub LightGridStudents_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LightGridStudents.MouseDoubleClick
        Dim vID As Integer = LightGridStudents.CurrentRow.Cells(0).Value

        'If the TextBox control is dynamic, find it 
        Dim vObj() As Object = FormBrowseAttendance.Controls.Find("editBoxStudentID", True)
        Dim vTB As PureComponents.EntrySet.Controls.EditBox = vObj(0)
        vTB.Text = vID

        MessageBox.Show(vTB.Text)

        Me.Close()
    End Sub

This handler is in the 3rd opened form and the 2nd opened form is FormBrowseAttendance.

If you try out my sample form you can see that same problem. I can send a value to the textbox in the 1st opened form from within the 2nd open form but can't do it from the 3rd opened form going to the 2nd open form.

Could this be a .net limitation?

Anyway, we appreciate all the help you have been providing.

Truly,
Emad
 
"Dim vTB As PureComponents.EntrySet.Controls.EditBox = vObj(0)"

Try
1. Me.Refresh()
2. EditBox.Refresh()

If neither of those work, try using a standard textbox in place of the PureComponents control and see is that works. If it does you will need to contact them! Certainly not a .NET issue....
 
Hi,

The refresh methods did not work so in the mean time we decided to use a combo box loaded with the data from the students table.

Later I will try to see if it works if the user clicks the students browse window from the main window instead of from the attendance browse window via a lookup button.

Truly,
Emad
 
Back
Top