On Thu, 21 Aug 2008 10:24:22 -0700, Ian <Freemanwrote :
I get the same behavior in VB.NET '05 when I am closing a modal dialog
form. I read on MSDN that the form's close() method should not be used
when forms are opened using .ShowDialog(). You should use dispose()
instead. This solved the issue for me.
Basically, the first time I enter the form, the columns were hidden as
they should be. After closing the form with close(), subsequent visits
to the form would show all columns as visible. When I closed the form
with dispose(), subsequent visits rendered the columns as they were set
in the designer.
Did you have a question?
In VB.NET, if you're seeing the behavior you describe, then you probably
have made the additional mistake of not explicitly instantiating your
dialog object before showing it. When you do that, VB.NET will use its
"default instance", which is the same for each invocation of the dialog.
This isn't possible in C# and so it would be obvious to the person using
the dialog whether they are reusing the same instance or creating a new
one each time they show the dialog.
As far as Close() vs Dispose() goes...yes, it's true that you need to call
Dispose() explicitly on forms shown with ShowDialog(). These forms are
not disposed implicitly when they are closed, because a common pattern of
usage is to close them and _then_ retrieve user input or other information
from the controls found in the form. Were the form to be disposed on
close, as non-modal forms are, these controls would also have already been
disposed by the time the code tries to get the data from them.
But this also means that simply calling Dispose() is usually not an
appropriate way to close a modal form. In particular, most modal forms do
in fact have data that the caller is going to want to get at after the
form's been closed. So the right thing to do is call Close() (which for a
modal form simply hides it), and then rely on the caller to call Dispose()
after they've gotten the information from the form that they want.
Pete