Hi,
I have three forms form1, form2, and form3. In form1 I have a button and datagridview. The button on clicking takes control into form3. Similarly in form2 also I have a button and a dgv. The button on click takes control to form3. Now in form3 I want to identify which forms button is pressed. I mean if I have clicked form1's button then I will access form1's dgv or if I have clicked form2's button then I will access form2's dgv. How to know which form's button I have clicked in form3?
thanks
Vimal KandasamyPosted May 27, 2009, 12:08 AM
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
sachi vasishtaPosted May 26, 2009, 9:43 AM
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
Suchit KhannaPosted May 25, 2009, 9:26 AM
Vimal KandasamyPosted May 25, 2009, 3:58 AM
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.
sachi vasishtaPosted May 25, 2009, 3:28 AM
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
Suchit KhannaPosted May 25, 2009, 2:17 AM