Skindeep2366
Skindeep2366

Reputation: 1559

Passing Variable from Windows form to Modal

Windows Forms, VB. I have searched the web for the correct answer to this and no dice. Either they are missing on what I am trying to accomplish or are in CSHARP making it harder for me to see what they are doing. I have a need to pass a record Id from the main windows form into a modal Dialog Load Event.. I have tried throwing a with param in but then I have to change the Load event params and vb flags it.. I am trying to pass the value of _CurrentProp which is an integer into the dialog. This is the dialog constructor and the load event inside that dialog..

Private Sub PropertySettingsMenuClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PropertyDetailsToolStripMenuItem.Click
Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.ShowDialog()
End Sub


Private Sub PropertySettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim _properties As New List(Of property_info)
_properties = db.property_info.ToList
    For Each a In _properties
        If Not p_settingsCityList.Items.Contains(a.city) Then
            p_settingsCityList.Items.Add(a.city)
        End If
    Next

    For Each b In _properties
        If Not p_settingsPropertyList.Items.Contains(b.property_Name) Then
            p_settingsPropertyList.Items.Add(Convert.ToString(b.idProperties) + " -- " + b.property_Name)
        End If
    Next
    p_settingsZipCode.ReadOnly = True
    p_settings_Address.ReadOnly = True
    p_settings_PropertyName.ReadOnly = True

End Sub

I am going to simply assign the value to a global variable inside the PropertySettings Class but everything I try seems to fail in one way or another... Any ideas...

Upvotes: 1

Views: 3751

Answers (1)

Olivier Jacot-Descombes
Olivier Jacot-Descombes

Reputation: 112269

Add a public property RecordID to your dialog window, then open the dialog like this

Dim _propertSettings As New PropertySettingsWindow()
_propertSettings.RecordID = 15
_propertSettings.ShowDialog()

In the dialog form you can simply access the record id with

_properties = db.property_info_by_id(RecordID).ToList   

Starting with .NET Framework 4.0, you can use auto-implemented properties

Public Property RecordID As Integer

With previous versions you would have to write

Private _recordID As Integer
Property RecordID As Integer
    Get
        Return _recordID
    End Get
    Set(ByVal value As Integer)
        _recordID = value
    End Set
End Property

Upvotes: 4

Related Questions