killing dlg in New()

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

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?
 
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
 
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.
 
Back
Top