I have a loop that takes file name from a listbox, performs a system() call, then moves that filename to another listbox. Problem is, it doesn't move the filenames over one at a time, but waits until the entire loop is finished and moves them all at once. What would I do to get it to perform how I want it to?
the loop:
for each( String^% file in filename )
{
int x = convert( file );
lbComplete->Items->Add( lbFiles->Items[0] ); // place the completed file
lbFiles->Items->Remove( lbFiles->Items[0] ); // in the other listbox
}
The function convert() that contains the system call:
int convert( String^ file )
{
std::stringstream ss;
std::string dir, fileAddress, fileName, outputDir;
...
return system( ss.str().c_str() );
}
You would need to call a refresh function at the end of your loop forcing it to redraw your listboxes otherwise it will wait until after your loop to do so.
for each( String^% file in filename )
{
int x = convert( file );
lbComplete->Items->Add( lbFiles->Items[0] ); // place the completed file
lbFiles->Items->Remove( lbFiles->Items[0] ); // in the other listbox
// INSERT REFRESH FUNCTION HERE
}
It's very common in GUI programming that methods called from the "event thread" or "event loop" need to finish before the changes they make are seen on the screen. That's regardless of the language or the environment. The usual way to avoid that problem on the things I'm most familiar with (like Java Swing) is to do the updates outside of the event loop, but use notifications (swing events) to tell the GUI to update the display occassionally.
Tell both listboxes to refresh themselves after moving an item.