Click to See Complete Forum and Search --> : Get text from child dialog


BlackOps
December 17th, 2007, 02:39 AM
Hello, i have simple database application, which shows data from database file. Now i want implement feature of finding by Name.. i have added new SQL statement to XSD schema...its ok..

now i have added new item - Form2. to the dialog. there is textBox1 on it. OK, and Cancel buttons.

now i want to activate this dialog, and type any name there...click OK, and after this it will show all records with this name. but problem is, from the Form1.cs it doesnt see a textBox1... cuz textBox1 is on the Form2.cs

here is the code:

private void form2ToolStripMenuItem_Click(object sender, EventArgs e)

{

Form2 myForm = new Form2();

if (myForm.ShowDialog() == DialogResult.OK)

{

// extract the data from the dialog

//MessageBox.Show(myForm.Name + " was entered into the database");

this.e_employeesTableAdapter.FillByName(this.swsDataSet.e_employees,);

}



}



what do i have to write down after this.swsDataSet.e_employees.... ?

thanks

BlackOps
December 17th, 2007, 02:46 AM
oh, i have figured a way... let me show u, and u say me is this good idea or not, SO:


i added
public String name;

to the Form2 class,

then i've added:
private void button1_Click(object sender, EventArgs e)

{

name = textBox1.Text;

}


to the Form2.cs

and changed the event handler in Form1.cs like that:

this.e_employeesTableAdapter.FillByName(this.swsDataSet.e_employees,myForm.name);

is this OK?

thanks

Tischnoetentoet
December 17th, 2007, 02:51 AM
It is working, but I would definitely advise to use properties instead of using a public variable.

BlackOps
December 17th, 2007, 03:10 AM
can u show it to me with code please?

Tischnoetentoet
December 17th, 2007, 03:27 AM
ok, change public string name to:

#region Variables
private string _name;
#endregion

#region Properties
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
#endregionUsing properties, you can determine whether variables are read-only or not. Or, can you check if setting a value is in a specific range (for example).