Q

How can I access the main form's controls from the dialog box?

I have a main form and another form which acts as a dialog box. From the main form, I am calling the dialog box with the following code:

Dim DialogB As New DialogB()

DialogB.ShowDialog()

This works great, but how can I access the main form's controls (i.e. frmRedem.lstBox.SelectedIndex) from the dialog box? If I use the same technique, the program will not start, and the help file's suggestion to use ParentForm does not work! I am using Windows XP.

What you're missing is that you need to use the CType function to cast the ParentForm property to access the parent. Here's an example of a function that will get the title of the parent form:
Public Sub GetParentText()
   Dim x as String
   x = CType(Me.ParentForm, Form1).Text
End Sub
This was first published in March 2003

Dig deeper on Win Development Resources

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchCloudComputing

SearchSoftwareQuality

SearchSOA

TheServerSide

SearchCloudApplications

Close