Dailycode.info

Short solution for short problems

Opening a window with ShowDialog in a window that is opened with ShowDialog.

I had a simple form that opened a search form. From this search form it was possible to open a sub search form. What happened was when you opened the sub search form, and found a value, selected it and returned to the (parent)search form, it ended up in the close handler of this form and closed it. After some searching around, Ii found out that the Dialog Result of the sub search form was effecting the dialog result of the search form. The solution I found was to explicitly set the dialog result of the search form to none after the sub search form returned its result.

For example: Lets say my search form is called from a main form using the ShowDialog. In this search form we call a second search form of type SearchSubForm.

Dim frmSubSearchForm As SearchSubForm = new SearchSubForm()

If frmSubSearchForm.ShowDialog = DialogResult.OK Then

'Do something 

End If

 

This code could generate the problem. So to solve this, you can set the dialog result of the search form to none like this:

Dim frmSubSearchForm As SearchSubForm = new SearchSubForm()

If frmSubSearchForm.ShowDialog = DialogResult.OK Then

       Me.DialogResult = DialogResult.None

'Do something 

End If

This solves the problem. I did not had the time to look into this problem in dept. It could be that it has something to do with the main page state or some other problem, but unfortunately I will not have time to investigate it.