60 635
Assignments Done
97,8%
Successfully Done
In April 2018

Answer to Question #31331 in C# for Armen Matevosyan

Question #31331
How to add from one form string to another form list?
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions