2012-02-28 169 views
0

我在父視圖中有一個數據網格。將選定值傳遞給子窗口

當我選擇在網格中的項目,

  1. 我想開一個子窗口

  2. 被選中的項值傳遞給子窗口

  3. 我需要根據所選值提交更改。

我正在修改以下代碼,這是我需要轉移到子窗口的點擊事件。

我可以從父視圖繼承域數據源嗎?

private void ApproveCmd_Click(object sender, RoutedEventArgs e) 
    { 
     PA_Request selReq =(PA_Request) this.onticPMA_RequestRadGridView.SelectedItem; 
     if (selReq != null) 
     { 
      ((PA_Request)this.PA_RequestRadGridView.SelectedItem).STATUS = "Approved"; 

      this.PA_RequestDomainDataSource.SubmitChanges(); 



     } 
    } 

    private void DissaproveCmd_Click(object sender, RoutedEventArgs e) 
    { 
     PA_Request selReq = (PA_Request)this.PA_RequestRadGridView.SelectedItem; 
     if (selReq != null) 
     { 
      ((PA_Request)this.PA_RequestRadGridView.SelectedItem).STATUS = "Disapproved"; 

      this.PA_RequestDomainDataSource.SubmitChanges(); 


     } 
    } 

    private void ApplyCmd_Click(object sender, RoutedEventArgs e) 
    { 
     PA_Request selReq = (PA_Request)this.PA_RequestRadGridView.SelectedItem; 
     if (selReq != null) 
     { 
      ((PA_Request)this.PA_RequestRadGridView.SelectedItem).STATUS = "Applied"; 

      this.PA_RequestDomainDataSource.SubmitChanges(); 

     } 

回答

0

好吧假設網格中有10個元素。當你點擊任何項目時,打開一個事件說ApproveCmd_Click。您需要先像這樣檢索發件人。

private void ApproveCmd_Click(object sender, RoutedEventArgs e) 
{ 
    var senderListBox = sender as ListBox; (Or any type you want) 
    var senderListBoxItem = senderListBox as senderListBoxItem; 
    string data = senderListBoxItem.Content; 
    //Now you have sender. 
    // Pass sender through constructor of the window 
    //Say you need to pass a string Create 

    var chieldWindow = new ChieldWindow(data); 
} 
在chield窗口

class ChieldWindow :Window 
{ 
    ChieldWindow(string input) 
    { 
     \\You got the data 
    } 
} 

還是讓我知道

相關問題