Transferring user input from a textBox of a form to a label of another form
-
Hi. I'm creating a small program that can take restaurant menu choices. I have a main form that takes all the user's choices and then another form that takes how many did the user ordered for a particular dish/menu. Now my problem is I can't show the quantity inputted by the user to the main form where i can also show all the menu/dishes that the user has ordered, the quantity of each dish, and the total amount he must pay. I have a class that gets the quantity but when i try to show it to the main form after entering the quantity, the value is still zero. How will I show the quantity to the main form after i enter it from another form? I'm thinking of another way but I feel that this solution is possible. this is the combobox from the main form:
OrderInfo customerChoices = new OrderInfo();
#region Appetizer ComboBox
private void cmboBoxAppetizer_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cmboBoxAppetizer.SelectedIndex)
{
case 0:
{frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); customerChoices.Appetizer = cmboBoxAppetizer.Text; label1.Text = customerChoices.Quantity } break; case 1: { frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); } break; case 2: { frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); } break; default: { } break; } } #endregion
then this is the form that takes the quantity:
public partial class frmQuantity : Form
{
OrderInfo customerChoices = new OrderInfo();public frmQuantity() { InitializeComponent(); } private void txtBoxQuantity\_TextChanged(object sender, EventArgs e) { txtBoxQuantity.MaxLength = Convert.ToInt32(txtBoxQuantity.Text); } private void btnOk\_Click(object sender, EventArgs e) { customerChoices.Quantity = Convert.ToInt32(txtBoxQuantity.Text);
-
Hi. I'm creating a small program that can take restaurant menu choices. I have a main form that takes all the user's choices and then another form that takes how many did the user ordered for a particular dish/menu. Now my problem is I can't show the quantity inputted by the user to the main form where i can also show all the menu/dishes that the user has ordered, the quantity of each dish, and the total amount he must pay. I have a class that gets the quantity but when i try to show it to the main form after entering the quantity, the value is still zero. How will I show the quantity to the main form after i enter it from another form? I'm thinking of another way but I feel that this solution is possible. this is the combobox from the main form:
OrderInfo customerChoices = new OrderInfo();
#region Appetizer ComboBox
private void cmboBoxAppetizer_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cmboBoxAppetizer.SelectedIndex)
{
case 0:
{frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); customerChoices.Appetizer = cmboBoxAppetizer.Text; label1.Text = customerChoices.Quantity } break; case 1: { frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); } break; case 2: { frmQuantity frmQuantity = new frmQuantity(); frmQuantity.Show(); } break; default: { } break; } } #endregion
then this is the form that takes the quantity:
public partial class frmQuantity : Form
{
OrderInfo customerChoices = new OrderInfo();public frmQuantity() { InitializeComponent(); } private void txtBoxQuantity\_TextChanged(object sender, EventArgs e) { txtBoxQuantity.MaxLength = Convert.ToInt32(txtBoxQuantity.Text); } private void btnOk\_Click(object sender, EventArgs e) { customerChoices.Quantity = Convert.ToInt32(txtBoxQuantity.Text);
gamer1127 wrote:
OrderInfo customerChoices = new OrderInfo();
You need to read a basic book on OO. Imagine you own two cars. Imagine you put a good stereo in one. Now, you're driving the other one. Do you have a good stereo ? Perhaps, but perhaps not. You have two different instances of OrderInfo, you set values in one, and the other is unaffected. You should use delegates to create communication between forms. Just google for articles explaining how delegates work, and go from there.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
gamer1127 wrote:
OrderInfo customerChoices = new OrderInfo();
You need to read a basic book on OO. Imagine you own two cars. Imagine you put a good stereo in one. Now, you're driving the other one. Do you have a good stereo ? Perhaps, but perhaps not. You have two different instances of OrderInfo, you set values in one, and the other is unaffected. You should use delegates to create communication between forms. Just google for articles explaining how delegates work, and go from there.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.