views:

343

answers:

3

I have a winform project which lists all the files in a specified folder. It allows the user to select a new destination for each file, and when the user has chosen the destinations for all files that he would like to be moved, it moves the files, one by one.

My next step is, I need to display a confirm form when the files are being moved, and add each file's name and destination to the confirm form as it is being moved.

My question is: How can I add more text to the confirm form's controls after I already loaded it (using confirm.showdialog() from my other form, without any user interaction? I imagine that I need to do it from the original form, because it needs to display each one when it starts to move that file, but I'm open to any suggestions:)

TIA

A: 

Wouldn't it be simpler to make another form instead of using preset dialogs?

that way you can just have a textbox that you populate and refresh

Eric
I am using another form, and I have a textbox on that form where I display the info.How can I refresh that textbox form the original form?I tried confirm.textbox1.refresh(), but that didn't do anything
A: 

You could do put all of the code to show the moving of the files inside the confirm dialog window.

But to give a more complete solution could you tell me how you are gathering the file moving information.

A Good solution would be to just pass in the list of the files to be moved and then perform the moving function in the dialog.

msarchet
Where would I put the code in the confirm dialog? If I put it in form load, it only loads the form once all the files are listed.thanks
+1  A: 

Both above answers are good.

If I understand correctly, your main form will allow one to select multiple files, then select their destination and launch the move process. If that's what you need, I would simply do the following:

  1. Create a new form that would report the process to the user, without requiring any interaction, but just to inform the user what file is being moved;
  2. Create an instance of a BackgroundWorker object, and call the file-move method from the BackgroundWorker.DoWork() method (within your main form);
  3. Flag your BackgroundWorker to report progress, then call the BackgroundWorker.ReportProgress() event handler from within your move-file method;
  4. Use the previously created list of file names to get its name and report it to your file-move dialog form while the file is being changed. A simple DataBinding over a Label should do the trick while you'll move your CurrencyManager to the next item within the list, or you could simpler use the list indexer to get the filename at a particular index;
  5. When the user launches the move process, get your filenames and and count them, then set your ProgressBar Maximum value to the number of files you have.
  6. The BackgroundWorker.ReportProgress() method takes an integer value as its argument, then, with your ProgressChanged() event handler, you will be able to display the name of the file being copied to your window by getting the filename at the index location, index given by your ReportProgress() method.

This will allow you to use the performance of a supplemental thread, without "freezing" your main thread from which your form has been created, then you will be able to simultaneously perform your file move, and display the filename to the progress-form, while illustrating to your user visually what the progress is about through your ProgressBar control, and displaying the filename as required.

Does this help?

Will Marcouiller
thanks a lot for your detailed response. I will get to work implementing it now...
I'm geting the following error with the background worker:{"ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."}any ideas?