I had the same problem and came up with an idea that is slightly different. In my scenario, I am making a flash card program for my youngest two children, and I would like to return the answer provided to the parent form (a new child form for each new question with a flash card so that the parent form can update the number on the left, how many are correct, how many incorrect, etc.) without adding values ββto the database. It seems to be too complicated. I did to create a class with 3 each type of variable. I figured there would be three types for each task.
This is an example of my new class:
namespace ClassNamespace { public class ValueHolder { public int intValue1 { get; set; } public int intValue2 { get; set; } public int intValue3 { get; set; } public long longValue1 { get; set; } . . . } }
I create a new ValueHolder (ValueHolder vh;) from the parent form and pass it to the child form. In the child form, I create a new ValueHolder and then set it equal to the ValueHolder object sent in the constructor of the child form class. Now that the enter key is pressed (answer given), I can set vh.intValue1 to this.answerBox.text; ... well, I have to use int.tryparse (); But you got the idea. I only need the vh.intValue1 link from the parent form to get the entered value.
Parent form:
for (int i = 0; i < limit; i++) { ValueHolder vh = new ValueHolder(); ChildClass cc = new ChildClass(vh); MessageBox.Show(vh.intValue1.ToString());
and child form:
ValueHolder vh; public ChildClass (ValueHolder vhIncoming) { vh = vhIncoming; } private void answerBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { vh.intValue1 = 1234; } }
This seems to be the easiest solution for my scenario. I know this question is old, but I wanted to add this option for everyone who is in a similar situation. Just add a class to your project, add more types or more types to the class as needed, repeat the repeat for future projects.
Calvin wilburn
source share