473,591 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) Handles Menu_CDL_New.Cl ick
Dim result As DialogResult = CDL2X_CDL_Pick. ShowDialog()
If result = DialogResult.OK Then
MainMDI.ActiveF orm.Refresh()
CDL.CDLfile = CDL2X_CDL_Pick. FileName
winnum = winnum + 1
Try
Dim NewCDLwin As New Analyze
NewCDLwin.Text = NewCDLwin.Text + " " + winnum.ToString
NewCDLwin.MdiPa rent = Me
NewCDLwin.Show( )
Catch ex As Exception
winnum = winnum - 1
MessageBox.Show (ex.Message, "Open CDL Failure",
MessageBoxButto ns.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 2050
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.goo glegroups.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
1872
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. One of the main problems at this point lies in cancelling the event. I have found that the TAB fires the onkeypress in NN, but not in IE. I can cancel the onkeypress fine in NN. The TAB fires the onkeydown in IE and can be cancelled in IE. ...
8
602
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 box that warns that their changes will be lost, and asks them to confirm whether to continue. Sounds simple Unfortunately, the ListView's SelectedIndexChanged event cannot be cancelled, and it's actually called for each change in the selection. So,...
7
2766
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 with the last value it had before the user changed it. Pretty typical Now, the user types some invalid value and clicks OK. The user gets a message saying the value is not valid, and the bad value is replaced with the last good one. So far, so...
6
1619
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. This form does things like setup event handlers on each control so that
10
2130
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 some other method? -- Chad Miller President and Director of Software Development Predictive Concepts, Inc. www.predictiveconcepts.com 407.327.9910
12
18394
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 the eventArgs in VB.net and neither its help is available in MSDN. I'm thank full to you in advance.
9
4033
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 iframe. CODE ===== <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en_US"
0
7934
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8225
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6639
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.