I have a very complicated windows application which has 8 forms. There are “Previous” and “Next” buttons on each form to back and forth for easily editing forms.
private void ShowNext()
{
if (FormNext == null)
FormNext = new SomeForm(this);
FormNext.Show();
this.Hide();
}
private void ShowPrev()
{
FormPrev.Show();
this.Hide();
}
private void btnNext_Click(object sender, EventArgs e)
{
ShowNext();
}
private void btnBack_Click(object sender, EventArgs e)
{
ShowPrev();
}
Each form will execute different sql insert table command. But the question is that I don’t want to finish all insertion on each form.
What I want to is to finish all in the last form once the user confirms the correct input values.
That means I have to pass all variables from the very beginning to the last one.
Question: can the memory hold all variables? How to pass them cross forms?
Thanks.
Define a static public field in your main form, and update the value in each sub forms. Finally select the field in your last form for insertion
Something on the following lines:
Here MyContainerClass could be some class defined in your code, which can hold all the values you want to persist. If its just a string, then you may create a list of string. Then in each form set value
In the last form you can access the values