2012-07-20 43 views
0

我有一個使用Dictionary作爲其數據源的UltraGrid。我想將字典傳遞給另一個(模態)窗體以進行操作,並將更改反映到父窗體上的字典中。Windows窗體 - 傳遞對象到模態窗體來填充,然後傳回

我能夠將字典傳遞給孩子的形式,放屁到我的心中高興,但沒有任何變化反映在父表單上的字典。我相信這是因爲子窗體上的字典參數沒有引用同一個對象。

我真的不想在參考字典中傳遞。模式形式有一個私有構造函數和一個公共靜態方法ShowForm()。我不使用它的實例。有人能給我一個骨頭嗎?

+0

你能證明你的一些代碼?打開子表單並傳遞字典的部分。 – Steve 2012-07-20 21:38:43

+0

謝謝你的迴應,史蒂夫。我能夠得到它的工作,並在下面發佈解決方案。 – lintmouse 2012-07-23 14:48:51

回答

0

好吧,我能得到這個做兩件事情的工作:

1)確保該字典將它傳遞給孩子的形式,而不是初始化一個空的字典子窗體之前進行初始化。

2)當子窗體關閉時,將字典指定回網格上的數據源。

這裏是父窗體的代碼顯示它在行動:

private void addColorCodeLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 
    { 
     var assignedColorCodes = 
      (Dictionary<string, string>)this.subtypeColorCodesUltraGrid.DataSource; 

     //Initialize a null dictionary so that SubtypeColorCodeForm will reference the same dictionary. 
     if (assignedColorCodes == null) 
      assignedColorCodes = new Dictionary<string, string>(); 

     SubtypeColorCodeForm.ShowForm(this, new ImageServerProxy(this.tbImagingUri.Text), 
      assignedColorCodes); 

     //Assign the updated dictionary back to the data source. 
     this.subtypeColorCodesUltraGrid.DataSource = assignedColorCodes; 
    }