As the topic states i want to use a streamwriter to write the listbox from form1, but the streamwriter is in form2. How do i get the data from form1 to form2?

I have the code to write everything out etc, all I need is help to get the data from form1 to form2, thanks.

You should make Form2 constructor take a ListBox as a parameter and then pass form1's ListBox as a parameter when initiating Form2.

An example:

When initiating Form2, pass that ListBox as a parameter:

Form2 form2 = new Form2([B]listBox1[/B]);

And edit Form2;s constructor:

// This will hold the listbox from Form1
ListBox listBox1;

public Form2(ListBox L)
   // Now this holds form1's listbox
   listBox1 = L;

Hope that helps.


Yep that did it.

Thank you very much for your help!

ı have a form like here. ıt have a listbox.
and ı have harita.cs (not a form so)

ı want to write ıtem to listbox which on form1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.