HighTechTalks DotNet Forums  

killing dlg in New()

Dotnet General Discussions microsoft.public.dotnet.general


Discuss killing dlg in New() in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
JB
 
Posts: n/a

Default killing dlg in New() - 12-10-2007 , 12:07 PM






Is there some polite way to cancel a dlg in the New() processing?

Private Sub OpenTheDlg
Dim dlg as New dlgGetAList(intID as Integer)
with dlg
If .ShowDialog= DialogResult.Cancel then
.dispose
return
end if
...
End Sub

In the dlg code
Friend Sub New(intID as Integer)
Me.New()

If False = CheckOnSomething(intID) Then
MsgBox( "nothing to process")
(First try)
Me.DialogResult = DialogResult.Cancel ' This just seems to be
ignored
' the
dlg continues to open
(Second try)
Me.Close ' the does kill the dlg but an exception is raised in
the calling
' sub on the line If .ShowDialog ....
End If

End Sub

What I want is implied by (First try) but it doesn't work. What I want is
to show the message box and then exit without the dlg ever becoming visible.
I also tried putting the test in the Load event and it does sort of work but
the dlg does flash on the screen after the msg box is closed. Any ideas?

--
JB

Reply With Quote
  #2  
Old   
RobertW
 
Posts: n/a

Default RE: killing dlg in New() - 12-10-2007 , 12:59 PM






Hi,

I know absolutely nothing about Visual Basic, but I think I understsand what
you're trying to do:

You are calling two separate functions there:
(1) New
(2) Show Dialog

In New you are setting a DialogResult, but at this point, no dialog has been
shown, so the cancel is irrelevant.

What you want to be doing in New is setting a flag (a Boolean property,
public is simplest modifier) and give it a name 'public boolean
dontshow=false; by default and set it to 'true' in new when you don't want it
to show.

Then, before you call ".ShowDialog" surround that with a check to 'if
..dontshow { .. }'. This way, ShowDialog never gets called if New() raised
the flag.

That would probably accomplish what you want.

Pardon any syntax mixing between vb and C#.

-Rob

"JB" wrote:

Quote:
Is there some polite way to cancel a dlg in the New() processing?

Private Sub OpenTheDlg
Dim dlg as New dlgGetAList(intID as Integer)
with dlg
If .ShowDialog= DialogResult.Cancel then
.dispose
return
end if
...
End Sub

In the dlg code
Friend Sub New(intID as Integer)
Me.New()

If False = CheckOnSomething(intID) Then
MsgBox( "nothing to process")
(First try)
Me.DialogResult = DialogResult.Cancel ' This just seems to be
ignored
' the
dlg continues to open
(Second try)
Me.Close ' the does kill the dlg but an exception is raised in
the calling
' sub on the line If .ShowDialog ....
End If

End Sub

What I want is implied by (First try) but it doesn't work. What I want is
to show the message box and then exit without the dlg ever becoming visible.
I also tried putting the test in the Load event and it does sort of work but
the dlg does flash on the screen after the msg box is closed. Any ideas?

--
JB

Reply With Quote
  #3  
Old   
JB
 
Posts: n/a

Default RE: killing dlg in New() - 12-10-2007 , 02:20 PM



Thanks for the reply. I think that will work

In case you are wondering, the dlg runs a query on a SQL database that can
be expensive which why the test is in the dlg and not in the calling sub. If
the query succeeds, the the dlg has the data, if not, then it quits. If the
test were in the calling sub, the query would have to be run twice.
--
JB


"RobertW" wrote:

Quote:
Hi,

I know absolutely nothing about Visual Basic, but I think I understsand what
you're trying to do:

You are calling two separate functions there:
(1) New
(2) Show Dialog

In New you are setting a DialogResult, but at this point, no dialog has been
shown, so the cancel is irrelevant.

What you want to be doing in New is setting a flag (a Boolean property,
public is simplest modifier) and give it a name 'public boolean
dontshow=false; by default and set it to 'true' in new when you don't want it
to show.

Then, before you call ".ShowDialog" surround that with a check to 'if
.dontshow { .. }'. This way, ShowDialog never gets called if New() raised
the flag.

That would probably accomplish what you want.

Pardon any syntax mixing between vb and C#.

-Rob

"JB" wrote:

Is there some polite way to cancel a dlg in the New() processing?

Private Sub OpenTheDlg
Dim dlg as New dlgGetAList(intID as Integer)
with dlg
If .ShowDialog= DialogResult.Cancel then
.dispose
return
end if
...
End Sub

In the dlg code
Friend Sub New(intID as Integer)
Me.New()

If False = CheckOnSomething(intID) Then
MsgBox( "nothing to process")
(First try)
Me.DialogResult = DialogResult.Cancel ' This just seems to be
ignored
' the
dlg continues to open
(Second try)
Me.Close ' the does kill the dlg but an exception is raised in
the calling
' sub on the line If .ShowDialog ....
End If

End Sub

What I want is implied by (First try) but it doesn't work. What I want is
to show the message box and then exit without the dlg ever becoming visible.
I also tried putting the test in the Load event and it does sort of work but
the dlg does flash on the screen after the msg box is closed. Any ideas?

--
JB

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.