473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cancelling form load event

Hi All,

I see that this topic was discussed back on august 23rd, but I didn't see a
real answer. I have a VB.NET MDI app. A particular menu action on the MDI
parent is to call an OpenFileDialog box. If the result is ok, I show a form
with related information about the file.

However, there are only specific files allowed. In the MDI child form load
event, I check the validity of the file (right version, not open in another
app, etc.). Based on a post I saw from Jay (repeated in the thread here on
august 23rd), I throw an exception if there's a problem with the file.

Here's some code. first, how I call the form (in the MDI Parent):

Protected Sub MDICDLNew_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Menu_CDL_New.Click
Dim result As DialogResult = CDL2X_CDL_Pick.ShowDialog()
If result = DialogResult.OK Then
MainMDI.ActiveForm.Refresh()
CDL.CDLfile = CDL2X_CDL_Pick.FileName
winnum = winnum + 1
Try
Dim NewCDLwin As New Analyze
NewCDLwin.Text = NewCDLwin.Text + " " + winnum.ToString
NewCDLwin.MdiParent = Me
NewCDLwin.Show()
Catch ex As Exception
winnum = winnum - 1
MessageBox.Show(ex.Message, "Open CDL Failure",
MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try
End If
End Sub

In the child form, I check a bunch of stuff about the file, and if it isn't
the right type of file, or the wrong version, or if it's open in another
app, I throw an exception in various locations throughout the form load
code:

Throw New Exception(CDL2X_CDL_Name.Text + " is not a supported CDL
Version!")

However, the form still loads! What am I missing? Based on Jay's post on
PCReview and again here, throwing an exception should cancel the load event,
but it doesn't.

any thoughts?

TIA
Lee


Nov 21 '05 #1
2 2040
lgbjr wrote:
In the child form, I check a bunch of stuff about the file, and if it isn't
the right type of file, or the wrong version, or if it's open in another
app, I throw an exception in various locations throughout the form load
code:


Probably the simplest solution to this problem is "Don't show the form
unless you need to!

Check all that stuff about the file before you show the child form:

If FileIsValid() Then
'show child form here
Else
MsgBox("invalid file")
End If

Nov 21 '05 #2
Hi Chrix,

In general, I agree, and I think that's what I'm going to have to do. In my
app, I have several different child forms, each with quite a few controls
and lots of code to perform various tasks associated with different types of
files. My goal was to keep all of the logic for each type of document in the
child form associated with the document type, but it looks ike I'm going to
have to move at least the initial verification stuff to the MDI parent.

Still, it seems to me that if an exception is thrown in the load event, the
form shouldn't load.

Cheers,
Lee

"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
lgbjr wrote:
In the child form, I check a bunch of stuff about the file, and if it
isn't
the right type of file, or the wrong version, or if it's open in another
app, I throw an exception in various locations throughout the form load
code:


Probably the simplest solution to this problem is "Don't show the form
unless you need to!

Check all that stuff about the file before you show the child form:

If FileIsValid() Then
'show child form here
Else
MsgBox("invalid file")
End If

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Paul THompson | last post by:
I have been working for some time to 1) detect tab and shift tab events 2) control the focus on the basis of these events. I have found that I can do this, but continue to have nagging problems. ...
8
by: InvisibleDuncan | last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message...
7
by: Marina | last post by:
Imagine a form with some fields and an OK buttons that saves the information. Each field has validation logic in the Validating event. If the input is not valid, the control's value is replaced...
6
by: PromisedOyster | last post by:
Hi How do I cancel an event in a class where that event is setup in another derived class. See example below. Thanks All our winforms are derived from one of our own classes, BaseForm....
10
by: Chad Miller | last post by:
I currently have a base form that I inherit. The base for has a custom event. The event will not raise threw the inherited form. I was wondering if events work threw inheritance or should I use...
12
by: Adil Akram | last post by:
I want to cancel an event from its event procedure on some condition, I know how to do this in VB6 i.e. by setting cancel=true. Please tell me how can I do this in VB.net I don't know how to use...
9
by: pvsundarram | last post by:
hey, i am trying to cancel the keydown event for certain keycodes( for eg:- enter key ).But the cancelling of this event is not happening in firefox. Is there any way to cancel the event in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.