passing class instance between classes

ساخت وبلاگ
In a Visual Studio Win Form project I have a DGV on a form which displays class objects created from an sql server. To update the data, the user clicks an Update button on the form. This opens a second form that lets the user select column(s) to update. After updating, form2 calls a method in form1 that displays updated object values. To display the updated values, the Update method needs to reference the existing instance of its class. So I need to pass the instance 'this' from form1 to form2, store the object instance, then pass it back to form1 after the update is complete. This is my approach.
Code:

public partial class Class1: Form
    {
public Class()
{
 InitializeComponent();
}

public Class1_Load()
{
Create and populate DGV.
}

public static void UpdateDGV(object form)
{
DataGridView dgv = form.
}

private void Update()
{
Class2 class2 = new Class2(this);
class2.visible = true;
}
}

In Class2
Code:

public partial class Class2: Form
    {

        public Class2(object X)
        {
            InitializeComponent();
           
        }

        public static object X { get; set; }

        private void Class2_Load()
{
//create form
}

        private void CheckOptions()
{
//update column(s)
}

Class1.method2(Class2.X);
this.Close();
}

I can't access the DGV in the Update method. Am I going about this the right way? Any guidance appreciated.
CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 177 تاريخ : شنبه 21 بهمن 1396 ساعت: 5:39