I have a form called privateOrder, and two other forms.

in the first form when I double click on a datagridview it opens the privateOrder form.

in the second form I have a button, when I click it also calls the privateOrder form.

I want to know if there is a way to distinguish what event calls the


Depending on the event called for PrivateOrder I want the privateOrder_Load Behave in two different situations.

I tried to use the "e" parameter but when privateOrder loads the "e" parameter is empty.

is there any idea?

Edited by adam84: n/a

8 Years
Discussion Span
Last Post by adam84

Instead of just using form1.show, in the form module you could overload the New method of the form and create a new property indicating who was it called from:

Public Class privateOrder
    Inherits Form


    ' Use this property to store who is calling the form
    ' and call it after it is created (in the load event)
    Public ReadOnly CalledFrom As CalledFromV

    Public Enum CalledFromV
    End Enum

    ' ...
    ' ...

    Public Sub New(ByVal From As CalledFromV)

        ' specify when creating the form who is calling it
        CalledFrom = From
    End Sub


End Class

the in the moment you create the new form you specify where is it being called from...

Private Sub DataGrid1_DoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
        Handles DataGrid1.DoubleClick

        ' ...
        ' ...

        ' After this, when the form loads you'll be able to know who called it
        ' just check the value of its CalledFrom property
        Dim NewOrder As New privateOrder(CalledFromV.FromDataGrid)
        ' if it would have been called from the button you could use:
        'Dim NewOrder As New privateOrder(CalledFromV.FromButton)

    End Sub

thank you so much Fernando_Gomez, it helped a lot :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.