arcross
asked on
MDI form - close exception
Hi,
this is the situation...
Ive got a MDI form, from a menu that MDI form opens a child form:
dim fNew as frmNewJob= New frmNewJob
fNew.MdiParent = Me
fNew.Show()
Now, from this child i open another child of the MDI form:
dim frm as new OtherChildForm
frm.MdiParent = Me.MdiParent
frm.Show()
When this second form, opens, in the load event, im checking if that form contains any data. If not, a dialog form is shown from there:
'// in load event...
If dv.Count = 0 Then
If MessageBox.Show("No data") = Windows.Forms.DialogResult .Yes Then
Dim frm As New DialogForm
If frm.ShowDialog = Windows.Forms.DialogResult .Cancel Then
Me.Close() '---->>> HERE EXCEPTION
Else
'// Scroll to last row
bs.MoveLast()
End If
Else
Me.Close() '-----> HERE EXCEPTION
End If
End If
The exception i get when i cancel that dialog form says:
"Value Close() cannot be called while doing the CreateHandle()"
Any ideas on this??????
Just a note, if i dont open the the child form from the other child, its fine.
dim frm as new OtherChildForm
frm.MdiParent = Me.MdiParent '---> IF I REMOVE THIS LINE, DONT GET THE EXCEPTION !
frm.Show()
this is the situation...
Ive got a MDI form, from a menu that MDI form opens a child form:
dim fNew as frmNewJob= New frmNewJob
fNew.MdiParent = Me
fNew.Show()
Now, from this child i open another child of the MDI form:
dim frm as new OtherChildForm
frm.MdiParent = Me.MdiParent
frm.Show()
When this second form, opens, in the load event, im checking if that form contains any data. If not, a dialog form is shown from there:
'// in load event...
If dv.Count = 0 Then
If MessageBox.Show("No data") = Windows.Forms.DialogResult
Dim frm As New DialogForm
If frm.ShowDialog = Windows.Forms.DialogResult
Me.Close() '---->>> HERE EXCEPTION
Else
'// Scroll to last row
bs.MoveLast()
End If
Else
Me.Close() '-----> HERE EXCEPTION
End If
End If
The exception i get when i cancel that dialog form says:
"Value Close() cannot be called while doing the CreateHandle()"
Any ideas on this??????
Just a note, if i dont open the the child form from the other child, its fine.
dim frm as new OtherChildForm
frm.MdiParent = Me.MdiParent '---> IF I REMOVE THIS LINE, DONT GET THE EXCEPTION !
frm.Show()
ASKER
Hi randy thanks for your response.
This is a similiar problem than mine.
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic25653.aspx
but i cant see the difference from mine.
This is a similiar problem than mine.
http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic25653.aspx
but i cant see the difference from mine.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>I don't think the first alternative will help.
shown event is new in .net 2.0 framework. it works perfectly, i am using it in my project.
shown event is new in .net 2.0 framework. it works perfectly, i am using it in my project.
Hello, appari,
Sorry. I read your post too quickly and somehow thought that you were talking about the Activate event. I don't (yet) have 2.0 and didn't know about the Shown event.
But even so, I think that just not showing the form if it's inappropriate to do so (i.e. your second alternative) is a better solution. The "validation" method could still reside in that form (as suggested in the OP's link).
Cheers,
Randy
Sorry. I read your post too quickly and somehow thought that you were talking about the Activate event. I don't (yet) have 2.0 and didn't know about the Shown event.
But even so, I think that just not showing the form if it's inappropriate to do so (i.e. your second alternative) is a better solution. The "validation" method could still reside in that form (as suggested in the OP's link).
Cheers,
Randy
ASKER
Thanks to you both!
I really apreaciate your help, i was going crackers with this!!!
Álvaro
I really apreaciate your help, i was going crackers with this!!!
Álvaro
That's interesting. It seems like it may be a timing issue. You could try putting a Timer on OtherChildForm. Move the Close method to the Tick event of the timer and where you are now doing "Me.Close" place "Timer1.Enabled = True".
It seems as if the Timer Interval can be as short as you like. I set an interval of 1 ms on the timer, and it seemed to solve the problem.
Cheers,
Randy