Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何理解以前的(Form1.cs)数据信息_C#_.net_Winforms_Entity Framework_Entity - Fatal编程技术网

C# 如何理解以前的(Form1.cs)数据信息

C# 如何理解以前的(Form1.cs)数据信息,c#,.net,winforms,entity-framework,entity,C#,.net,Winforms,Entity Framework,Entity,当用户双击Datagridviewı调用此函数时,我有一些代码: public void GoBackMain() { if (dgvCariRehber.CurrentRow.Index != -1) { cariModel.Id = Convert.ToInt32(dgvCariRehber.CurrentRow.Cells["Id"].Value); using

当用户双击Datagridviewı调用此函数时,我有一些代码:

public void GoBackMain()
        {
            if (dgvCariRehber.CurrentRow.Index != -1)
            {
                cariModel.Id = Convert.ToInt32(dgvCariRehber.CurrentRow.Cells["Id"].Value);
                using (Entities db = new Entities())
                {
                    frmMain main = new frmMain();
                    cariModel = db.xcaSabits.Where(x => x.Id == cariModel.Id).FirstOrDefault();
                    main.lblCariID.Text = cariModel.Id.ToString(); // cariSabitte güncelleme için id yi gönder.
                    main.txtCariKodu.Text = cariModel.cariKodu;

                    main.Show();
                    this.Hide();
                }
            }
        }

但是如果以前的表格打开了,我想换一张表格。不要只走主要路线。ı如何完成此表单部分的参数化

在该表单上创建公共属性,如:
public-IForm调用者{get;set;}=main
然后,在调用当前表单之前,使用要从中调用的表单设置该属性,例如
formWithGridOn.Caller=this;
formWithGridOn.Show();
this.Hide()
然后需要将上面列出的代码更改为
Caller.Show();this.Hide()

我认为接口是IForm的,但那必须是表单的接口


希望这能有所帮助。

好的,但是如果ı有两个表单要返回,那么ı如何捕获上一个表单的数据?ıfıhave Caller2?相同的原则,创建一个可以存储数据的属性,然后目标可以回调以获取数据。如何使用formWithGridOn表单了解哪个表单即将到来?ı不能同时执行Caller.lblID和Caller2.lblID。函数不理解,如果块传递True,则调用窗体将属性调用者设置为自身。这意味着被调用的表单引用了调用它的表单。