Answer to Question #31331 in C# for Armen Matevosyan

Question #31331
How to add from one form string to another form list?
1
Expert's answer
2013-06-19T09:23:56-0400
You can’t have direct access from one form to another form data. You must append to your project new class file, for example DataClass.cs. There you need to describe a new static class at the same namespace as your project. Fields of this class must be static too. So you can use this fields to store data from one form and restore in another form. Instance of this class does not declare. You can use it by ClassName.FieldName . Simple example of such class:


Filename DataClass.cs :


using System;
using System.Collections.Generic;
using System.Text;


namespace project
{
public static class DataClass
{
public static string storeData;
}
}




Now you can use field storeData to do the transfer of data between your forms. For example from textBox1 at Form1 to listBox1 at Form2:


Filename Form1.cs :


…
namespace project
{
…
DataClass.storeData = textBox1.Text;
…
}


Filename Form2.cs:


…
namespace project
{
…
listBox1.Items.Add(DataClass.storeData);
…
}






That’s all. Enjoy

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS