0
Sachi,you have to pass current object of form1 or form2 to form3.Then only changes made in form3 will affect form1 & form2.
like
in form1
Form3 f=new Form3("form1",this);
f.showDialog();
and in form3
String formname;
Form1 f1;
public Form3(String fname,Form1 obj)
{
formname=fname;
f1=obj;
}
after that access it like
f1.dataGridView1.DataSource
0
thanks vimal.
Vimal I have a small doubt, In form3 if I want to access form1 or form2's dgv or other controls like form1.dataGridView1.DataSource then I have to use form1 and form2's objects right , but Iwant to know whether I have to just declare form1 and form2's object such as
Form1 form1;
Form2 form2;
in form3, or I have to do something more to access dgv or other contols of form1 or form2 in form3.
Thanks
0
Sachi I think Vimal clarified it with code, but If still there is some issue, could you please share the code you are using, may be it could give a clear picture.
0
Sachi,you can achieve this by passing info via overloaded constructor.thats enough.
I have used below code to identify which form for my applications.
in form1
Form3 f=new Form3("form1");
f.showDialog();
in form2
Form3 f=new Form3("form2");
f.showDialog();
and in form3
String formname;
public Form3(String fname)
{
formname=fname;
}
and in form3's loading event or other events
just check like
if(formname=="form1")
{
//code to access form1's dgv and others
}
if(formname=="form2")
{
//code to access form2's dgv and others
}
whenever you need, just refer formname varible to identify which form's button is clicked.
0
suchit I know how to write overloaded constructor and also I know to set form1 and form2's button's modifer property to public, but I want to know which property I have to use to know which form's button is clicked? like
form1.button1.? - here I am not getting the solution
0
One possible solution would be to create an overloaded constructor for Form3 and wherever you are instantiating the Form3 in your code pass the button clicked as a parameter to Form3 overloaded constructor, which you could catch in the Form3 and process accordingly.