hi, i just figured out how to write to a csv file form a textbox, i have the following code:

private void BtnOpslaan_Click(object sender, EventArgs e)
        {
            string[] lines = { textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text};
            System.IO.File.WriteAllLines(@"C:\output.csv", lines);
        }

but i was wondering how i can write to the same csv file from some other textboxes on another form. maby you know how i could fix this ;)
also i need to make the piece

(@"C:\output.csv", lines);

editable... so i can choose my own place where to place the file...

another solution would be if i can write text from form2 to and invisable textbox in form1...
maby you know how i could do that?
can't realy figure out how sending info between forms work..
alot different from delphi...

Hi

What you need to understand is that once you instanciate an object(i.e Form2 f2 = new Form2) you can access any public member(field, method...) declare in that object throuth the dot notation( i.e f2.textBox1 ).

If you have a form lets call it 'Form1' and this form has a 'TextBox' this text box is a field in that form. By default when you drag and drop a Visual Studio(or Visual C# Express) add a private field to the Class Form1.

So what you can do is expose this field as a public propery or change the access modifier of the field to public(not recomended).


A simpler way //maybe this was all you want it to 'hear' ;-)

form1:

Form2 _f2;
        private void button1_Click(object sender, EventArgs e)
        {
            _f2 = new Form2();
            _f2.Show();
        }

        private void btnFetchText_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = _f2.Controls["textBox1"].Text;       
        }

note:I oversimplified the use of access modifiers for the sake of clarity.

Hope this help.

Regards,
Camilo

FrmAdvocaat form2 = new FrmAdvocaat();
this.AddOwnedForm(form2);
form2.Show();
this.textBox6.Text = FrmAdvocaat.controls["textbox1"].Text;

why do i get error @ FrmAdvocaat...
the error says:
Error 1 'WindowsApplication1.FrmAdvocaat' does not contain a definition for 'controls'

you have any idee how i could make this code work correct?

Hi,

Remember that C# is case sensitives this means that controls != Controls

Regards,
Camilo

ok, changed it...
but now i get this error:
Error 1 An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Controls.get'

Hi,

Controls it's not a static property but a class one. You need to call it like this with the object instance

form2.Controls["textBox1"].Text

in your pass code snipped you write "textbox" are you sure that is not "textBox" instead. Check this or you are going to get another error.

Regards,
Camilo

ok i have no more errors now...
but also no text in my textboxes on form1...
how should i move the text from textBox1 on form2 to textBox6 on form1?
with this code nothing happens:

Frm2 form2 = new Frm2();
            this.textBox6.Text = form2.Controls["textBox1"].Text;

but also no errors...but when i have that on button click... nothing happens... no text appears in textBox6 on form1....

Hi,

You need to place this line of code
Form2 form2 = new Form2();
outside of the method's body, if you let the instanciation of the form inside of the handler every time you click the button you create a new form so the textBox1.Text property have the default value, an empty string.

Camilo

ok tanx for help :)

string[] lines = { textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox6.Text, textBox7.Text, textBox8.Text, textBox9.Text, textBox10.Text};

now have this line to write... but how can i @ an item before textBox1.text? what makes the output by example:

name;<inputed name>

im trying to move a character around a screen. i cant seem to find the right code that will recognise the key being pressed down. my current code is something like;

if(this.KeyDown += Keys.w)
Character.position.Y = position.Y+1;

this has nothing to do with my question...
anyone know the answere on my question?

Hi

Sweet12 I'd recomend you to start another thread. I dont quit get your question in the if statement you have tha += operator an applying this operator doesnt return a 'bool' type that is what is expected. Examples of operators that return 'bool' are ( == , != , !). Even thouth I respond to your question put it on a new thread. I am interested and I'll follow it.

Regards,
Camilo

Import the Microsoft.Office.Interop.Excel.dll and inherit it in your application. For e.g.
using Microsoft.Office.Interop.Excel or using Excel=Microsoft.Office.Interop.Excel

· Inherit System.IO namespace. For e.g. using System.IO

Following code demonstrate how to write Data in XML file from dataset:
<<snip>>

Be a part of the DaniWeb community

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