问题
I want to add data in 2 data gridview but they are in separate form how will i do it? The datagridview1 is in form1 and the datagridview2 is in form2. Because in form1 they cant see the data gridview2 because it is on the other form.
回答1:
You can do it like this ... In form 1 create a property
private static Form1 instance1;
public string propertyForm1;
public static Form1 Instance1
{
get
{
if (instance1 == null)
instance1 = new Form1();
return instance1;
}
}
And, in Form2
private static Form1 instance2;
public string propertyForm2;
public static Form2 Instance2
{
get
{
if (instance2 == null)
instance2 = new Form2();
return instance2;
}
}
Now you can access this property in either of any Form1 or Form2 or any Forms/Classes within your project like this...
Form1.Instance.propertyForm1 = "your assigned value from form2";
Form2.Instance.propertyForm2 = "your assigned value from form1";
Hope this helps you. And, dont forget to mark as answer if this worked for you.
来源:https://stackoverflow.com/questions/41649154/adding-data-separate-data-grid-view