1

Hi I have a form which is called by several other forms via the 'showdialog()' command I'd like it to do different things depending on which form it's called from

so I need to get the name of the parent form. I try with Me.Parent.Name or Me.Owner.Name I always get nothing value.

how can I get the form father that called the showdialog command?

Peter Macej
  • 4,831
  • 22
  • 49
GuidoM.
  • 27
  • 4

1 Answers1

1

There is no parent. That is only relevant for child controls. If you add a Button to a form, the form is the parent of the Button. Your form, like most, is a top-level window, so it has no parent.

There is no owner unless you specify one. The way to do that is to pass the owner when you call ShowDialog, i.e.

Using dialogue As New DialogueForm
    dialogue.ShowDialog(Me)
End Using

The dialogue will then be able to access the calling form via its Owner property.

Note that you shouldn't be interested in the Name of the owner but rather its type, e.g.

Dim ownerType = Owner.GetType()

If ownerType Is GetType(Form1) Then
    '...
End If
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • How can i pass Form1..Form2..Form3 variable to datagridview? Dim ownerType = Owner.GetType() Dim id As Integer = ownerType.name.DataGridView1.CurrentRow.Cells(0).Value.ToString – GuidoM. Apr 04 '23 at 12:48
  • 1
    @GuidoM., the comments for the answer is not the place to ask a new question. If you have a question, post a new question. – jmcilhinney Apr 04 '23 at 14:33