John John -3 years ago 116 Question

Call a windows form dynamically by its title in

I'm stuck with something that I have tried to overcome before and couldn't.
Last time I worked around it, but I really need to nail this down.

I have a multi-instance form which lists details of jobs, so a user may have 6 or so instances of this form open, all with different info. Lets call that form A.

Within form A there is an option to assign that job to a user.
Clicking that link label opens a new form using showdialog where a combobox is populated with logged in users... Lets call that form B.

What I want to do is have the value selected on form B passed back to form A, however because form A has multiple instances, I'm not sure how to call it.

Form A is JobDetails.vb, and always has a form title of "Job XXXXX Details", so I was hoping there was a way I could use the title to call it.

Hope that all make sense! Thanks in advance, and apologies if its a dumb question. I feel like this should be something obvious, but I just can't achieve it.

Answer Source

As shown on the help page of ShowDialog, you can easily alter the main form when the dialog-form is closed. So you could do something like this:

Public Sub ShowMyDialogBox()
    Dim testDialog As New Form2()

    ' Show testDialog as a modal dialog and determine if DialogResult = OK.
    If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then

        Me.Text = String.Format("Jobs of {0}", testDialog.cmboUsers.SelectedValue)
        Me.Text = "Jobs"
    End If
End Sub 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download