2016-04-05 7 views
0

私は2つの形式を持っています 最初のものはFrmReceiveItemsです。それで2番目のものを表示することができます FrmItemSearchです。 2番目の方法では、最初の形式でDataGridViewに追加する項目を選択できます。問題は、アイテムを追加するたびに、最初のフォームから新しいオブジェクトが作成されることです。選択したすべてのアイテムを最初に開いたフォームに追加します。C#後ろの形の情報を取得する

private void dgv_ItemsSearch_CellContentClick(object sender, DataGridViewCellEventArgs e) 
{ 
    try 
    { 
     //Connection obj = new Connection(); 
     //Connection.FrmChose = 10; 
     FrmRecieveItemsVoucher FRI = new FrmRecieveItemsVoucher(); 

     Form frmT = Application.OpenForms["FRI"]; 
     int value = Connection.FrmChose; 
     if (value == 10) 
     { 
      FRI.dataGridView_ItemsVoucher.Rows.Add(); 
      int CurrentRowIndex = FRI.dataGridView_ItemsVoucher.Rows.Count; 
      FRI.dataGridView_ItemsVoucher.Rows[CurrentRowIndex - 1].Cells[0].Value = dgv_ItemsSearch.CurrentRow.Cells[2].Value; 
      FRI.dataGridView_ItemsVoucher.Rows[CurrentRowIndex - 1].Cells[1].Value = dgv_ItemsSearch.CurrentRow.Cells[1].Value; 
      // here I try to test 
      if (frmT != null) 
      { 
       this.Dispose(); 
      } 
      else 
      { 
       FRI.Show(); 
      }    
     } 
     else 
     { 
      FrmItems frmItems = new FrmItems(); 
      //frmCust.btn_new(sender,e); 
      string Code = Convert.ToString(dgv_ItemsSearch.CurrentRow.Cells[2].Value); 
      this.Dispose(); 
      frmItems.Show(); 
      frmItems.Show_Record_data(Code); 
     } 
    } 
    catch (Exception Ex) 
    { 
     MessageBox.Show(Ex.Message); 
    } 
} 

enter image description here

+0

あなたの問題を説明する私たちに、最小限の完全かつ検証可能な例を示してください:http://stackoverflow.com/help/mcve – Fabjan

答えて

0

はよくこれを実現する方法はたくさんあります:私は、最初の形式のいずれかのオブジェクトは、次のよう..開いているかどうかをテストしてみてください。私が個人的に行っていることは、BindingListを作成し、そのリストにListChangedイベントを設定して、2番目のフォームでリロードをトリガーすることです。

+0

[OK]を、次のコードでは、と するvar FrmRecieveItemsの=のApplication.OpenForms [「FrmRecieveItemsVoucher」]私と一緒に動作しますFrmRecieveItemsVoucher; –

関連する問題