So_Im_Told So_Im_Told - 21 days ago 7
C# Question

When a user selects a seat the quantity it has to be the same as the amount of tickets

I have an assignment I am doing and user can select and artist and the amount of tickets per artist but I am unsure how to make it so when I click a seat I can only click the amount of seats I purchased in the previous screen.

I am using GlobalVariables and unsure what to do from this point.

int quantity = GlobalVariables.SeatQuantity + 1;
lblSeatQuantity.Text = Convert.ToString(GlobalVariables.SeatQuantity = quantity);

Answer

I assume you have the following issue:

  1. Form: Enter the Quantity
  2. Form Do something with the Quantity.

So you already should have something like this in your first WinForm:

private void OpenSecondForm() {
  Form2 form2=new Form2();
  form2.ShowDialog();
}

All you have to do is to add a public Property to your second form:

public class Form2:Form {
  public int SeatsSelected {get;set;}
}

Now you can assign the value before displaying the form:

private void OpenSecondForm() {
  Form2 form2=new Form2();
  form2.SeatsSelected=quantity;
  form2.ShowDialog();
}

and within the second Form you can do anything you want with that value e.g.

  MessageBox.Show(string.Format("You selected {0} seats!",SeatsSelected));