2012-03-28 125 views
1

Windows Forms,VB。我已經在網上搜索了正確的答案,沒有骰子。要麼他們錯過了我正在努力完成的事情,要麼在CSHARP中讓我很難看到他們在做什麼。我有一個需要從主窗口窗體傳遞一個記錄Id到一個模態對話負載事件..我已經嘗試拋出一個參數,但後來我不得不改變Load事件參數和VB標誌它..我試圖將_CurrentProp的值作爲整數傳遞給對話框。這是對話框構造和對話框內加載事件..從Windows窗體傳遞變量到Modal

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類中,但一切我嘗試似乎這樣或那樣的失敗。 ..任何想法...

回答

4

公共財產RecordID添加到您的對話框窗口,然後打開這樣

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

對話框在該對話框的形式,你可以簡單地用

訪問記錄id
_properties = db.property_info_by_id(RecordID).ToList 

與.NET框架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 
+2

+1或使它參數在窗體的構造函數中設置主屬性 - 兩者同等有效。 – Bridge 2012-03-28 16:24:19

+0

非常感謝,我忘記了我在最後一個vb.net mvc3項目中使用了很多它們。 – Skindeep2366 2012-03-28 16:25:43

+0

是的,一個'Form'只是一個類,你可以用它來做任何事情...... – 2012-03-28 16:41:46

相關問題