0

I have a foreach loop that I need to pause in order to allow user input on the form.

foreach (XmlNode node2 in xmlFile)
   {
       ...get currentRow from XML file
       ...update form label

       ???wait for user to enter data on form and press button
   }

Is there any sort of wait-for-user-input function in C# that I can use to do this?

UPDATE:

Based on the feedback I have successfully modified the program to:

  • Load the XML list into a Queue (using the ForEach loop)
  • Setup the user input to iterate through the Queue (remove top item, show next top item)
2
  • Is the input form always displayed to the user? Do you just want to pause the foreach loop when the user starts entering information? Commented Sep 1, 2011 at 19:49
  • I prefer usually to do event driven behaviours. Usually they are more clean than nesting modal forms. Commented Sep 1, 2011 at 19:55

4 Answers 4

2

Create you input form (use visual studio designer, is really simple), then show it in the loop by calling ShowDialog():

foreach(XmlNode node2 in xmlFile)
{
   //...
   MyInputForm form = new MyInputForm();
   form.ShowDialog(); // it waits until user close the input form
   var input = form.PropertyContainingInputFromTheUser;
   //...use the input

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

Comments

1

You can open a modal form where the user can make the input.

If you want to stay on the same form all the time you better copy all nodes to an Queue<XmlNode>, process one at a time and when the user presses the button pick the next item in the Queue until the queue is empty.

Comments

1

One way to do it would be to do a while loop which keeps checking for a value. However; depending on how you implement this and the overall structure of the application, this might cause the application to become unresponsive.

Comments

1

I would not use this design. I would have a form that shows and maybe loop using a control on the form - not displaying a new form for every instance. Load the data into a data grid and let the user edit all of it and save at one time.

Comments

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.