I use this code to open a FileDialog, choose a file and press OK.

It works fine, but when I press OK in the fileDialog, the FileDialog doesn´t close after pressing OK the first time. The dialog blinks one time and are still open.
The second time I press OK, the openfileDialog will close.

What can I do to make it close when I press OK the first time ?

openFileDialog1->ShowDialog();

 if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
	
	 textBox5->Text = openFileDialog1->FileName;
}

Recommended Answers

All 2 Replies

Didn't you see that you show TWO open file dialog windows? You close the 1st dialog and immediately show the 2nd one in if expression...
What for the 1st line of your snippet?

Please, next time use code tag properly:
[code=c++] text

[/code]

I see, I thought by first show the dialog and THEN make an if statement of what was choosen in the dialog.
But this works well. Thank you for help...

if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
	
	 textBox5->Text = openFileDialog1->FileName;
}

Didn't you see that you show TWO open file dialog windows? You close the 1st dialog and immediately show the 2nd one in if expression...
What for the 1st line of your snippet?

Please, next time use code tag properly:
[code=c++] text

[/code]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.