Problem solve Get help with specific problems with your technologies, process and projects.

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()


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

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.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.