将变量从Windows窗体传递到模态

时间:2012-03-28 16:11:27

标签: vb.net winforms

Windows窗体,VB。我在网上搜索了这个没有骰子的正确答案。要么他们缺少我想要完成的东西,要么在CSHARP中,这让我更难以看到他们在做什么。我需要将主窗口窗体中的记录ID传递给模态对话框加载事件..我已经尝试抛出一个带参数然后我必须更改加载事件参数和vb标记它..我正在尝试将_CurrentProp的值(整数)传递给对话框。这是对话框构造函数和该对话框中的load事件..

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

我将简单地将值分配给PropertySettings类中的全局变量,但我尝试的所有内容似乎都以某种方式失败......任何想法......

1 个答案:

答案 0 :(得分:4)

将公共属性RecordID添加到对话框窗口,然后打开像这样的对话框

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

在对话框表单中,您只需使用

访问记录ID即可
_properties = db.property_info_by_id(RecordID).ToList   

从.NET Framework 4.0开始,您可以使用自动实现的属性

Public Property RecordID As Integer

使用以前的版本,您必须编写

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