-1

Firstly, my English is bad, I'm sorry.

I want textbox (in Form2.cs) text to displaying MainForm.cs When I apply the following codes, displaying blank message.

MainForm.cs

private void btnFilitre_ItemClick(object sender,DevExpress.XtraBars.ItemClickEventArgs e)
{
     ...
     Form2 f2 = new Form2();
     f2.Show();
}

private void workingFunction()
{
    CommClass com = new CommClass();
    MessageBox.Show(comm.Sorgu ); 
}

Form2.cs

 private void button1_Click(object sender, EventArgs e)
 {
     Form1 f1 = new Form1();
     CommClass comm = new CommClass();
     comm.Sorgu = textBox1.Text;
     f1.workingFunction();
     Hide();
 }

CommClass.cs

 public string Sorgu { get; set; }

What is the problem?

Nico
  • 12,493
  • 5
  • 42
  • 62
  • You are instantiating a new instance of CommClass in each place. workingFunction is not using the same CommClass you declared in the button1_click – AndrewP Mar 05 '17 at 23:00

1 Answers1

0

You need to pass the argument in. In Form1 make this change:

public void workingFunction(CommClass comm)
{
    MessageBox.Show(comm.Sorgu ); 
}

And in Form2, you will need to keep track of your Form1 reference, instead of creating a new one, and then pass in your CommClass object:

private void button1_Click(object sender, EventArgs e)
{
    CommClass comm = new CommClass();
    comm.Sorgu = textBox1.Text;
    f1.workingFunction(comm);
    Hide();
}
Tim
  • 5,940
  • 1
  • 12
  • 18