C#在后面的表单中获取信息

时间:2016-04-05 11:49:32

标签: c# forms

我有两种形式 第一个是FrmReceiveItems,我可以从中显示第二个。{1}} FrmItemSearch。在第二个中,我可以选择某个项目添加到第一个表单中的DataGridView。问题是每当我添加一个项目时,我将从第一个表单中获得一个新对象。我希望将所有选定的项目添加到第一个打开的表单中。我尝试测试是否打开第一个表单的任何对象..如下:

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

1 个答案:

答案 0 :(得分:0)

有很多方法可以实现这一目标。我个人想要的是创建BindingList并在该列表上设置ListChanged事件,然后以第二种形式触发重新加载。