开发者

Allow userform input from a foreach loop?

开发者 https://www.devze.com 2023-04-01 17:29 出处:网络
I have a foreach loop that I need to pause in order to allow user input on the form. foreach (XmlNode node2 in xml开发者_开发技巧File)

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

foreach (XmlNode node2 in xml开发者_开发技巧File)
   {
       ...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)


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

}


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号