How to interrupt loading of form

  • Thread starter Thread starter Tore Gylver
  • Start date Start date
T

Tore Gylver

I have a windows form bound to a dataset. Data is loaded
into the the forms dataset in the forms load event.
Depending on the data loaded there are cases where I dont
want to open the form but rather give the operator a
warning message, then close the form so that it is not at
all visible for the operator.

I do this with a msgbox followed by me.close in the form
load event, but the me.close then gives an exception.

How can I prevent the form from opening? And I do want to
close the form, not only hide it.

Regards

Tore Gylver
 
* "Tore Gylver said:
I have a windows form bound to a dataset. Data is loaded
into the the forms dataset in the forms load event.
Depending on the data loaded there are cases where I dont
want to open the form but rather give the operator a
warning message, then close the form so that it is not at
all visible for the operator.

I do this with a msgbox followed by me.close in the form
load event, but the me.close then gives an exception.

The only way is to throw an exception. This exception can be catched in
the code that is used to show the form.
 
I still have a problem to see how my problem can be
solved. Since I am not very familiar with exception
handling in .Net (and .Net in general) I would appreciate
some sample codelines in VB.

I understand I have to throw an exception in the form
where my error situation is detected. Then I wonder where
my Try - Catch blocks should be, in the form where the
error is detected or in the form that runs Formname.Show?

What should be the codeline in my catch-block to prevent
the new form (with error) from showing? The error is
detected in the forms load event and I need the loading
to be interrupted in some way.


Regards

Tore Gylver
 
Hi Tore,

I'm not sure what the problem is , because the following snippet works fine
in my test program.
<code>
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
MsgBox("Hello")
Close()
End Sub
</code>
could you show me some code snippet of your onload event and also some more
information on that exception?
I'll look into it and find some clue.
Thanks!

Also, here is a small snippet of exception handling in VB.NET, I hope it
will be helpful:
<code>
Dim f1 As New Form1
Try
f1.Show()
Catch ex As MyException
Exit Try
Catch ex As Exception
MsgBox("f1 throws an unhandled exception")
End Try
<code>


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
Hi Ying-Shen Yu,

//Form1(Caller) -> Form2(called as a model dialog)

If a form(Form1) is invoking another form(Form2) as a model dialog
(frm2.ShowDialog(this);),
then in Form2' load event, trying to close the form2 does NOT do so?

How can this be acheived?


Regards,
Sankalp
 
Hi Sankalp,

I'm unable to repro the problem you described, could you give me a repro
sample for this issue?
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
Hi Sankalp,

Thanks for your repro sample,
However, I'm not able to repro the problem on my system,
I noticed that you are using VS.NET 2002 and the .NET Framework version
should be v1.0
while my sytem is VS.NET 2003 and .NET Framework v1.1.
Have you tested the sample on v1.1?

Be free to reply to this thread if you still have problem on v1.1.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 
Back
Top