0
for (int i = 0; i < service.journeys.Count; i++)
{
    var popup = new JourneyPopup();

    // Fill out the form
    popup.txtJourney.Text = service.journeys[i].journeyCode;
    popup.txtDays.Text = service.journeys[i].daysOfWeek;
    popup.txtDeparture.Text = service.journeys[i].departureTime;
    popup.txtOrigin.Text = service.journeys[i].description;

    popup.Show();
}

Inside my JourneyPopup form I have a button called 'done'. I need to iterate the for loop only after 'done' has been clicked. How can I do this?

2
  • Use the click event. msdn.microsoft.com/en-us/library/… Commented Dec 23, 2013 at 17:04
  • @DROPtableusers Sure, but how do I pause the for loop whilst it waits for the click event? Commented Dec 23, 2013 at 17:04

2 Answers 2

5

You might try the .ShowDialog() function. It will not return until the dialog/form has closed.

Sign up to request clarification or add additional context in comments.

Comments

0

I assume that it's a WinForm application and JourneyPopup is derived from Form. Then, in the Forms designer, you can give the button a custom int value, that will be returned by the Form.Show() methods when the button was pressed.

At the end of your loop, you then can check this:

if (popup.ShowDialog() != <Returnvalue from button>)
{
    break;
}

2 Comments

Are you assuming WinForms or WPF? The function exists in both, but has different return values.
WinForms. Didn't even know that the Show() method(s) also exist in WPF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.