How do you make a dialog forget its fields when reshown?

  • Thread starter Thread starter HONOREDANCESTOR
  • Start date Start date
H

HONOREDANCESTOR

I have code like this
TheDialog.ShowDialog
If the user fills in the fields, and then hits OK, and then later
comes back to the dialog to add a different item, the dialog is still
filled with the data he entered the first time. To prevent this, I
could just set every text box to an empty string, and the selections
on every combo box would also have to be reset somehow.
But is there an easier way?
 
I have code like this
TheDialog.ShowDialog
If the user fills in the fields, and then hits OK, and then later
comes back to the dialog to add a different item, the dialog is still
filled with the data he entered the first time. To prevent this, I
could just set every text box to an empty string, and the selections
on every combo box would also have to be reset somehow.
But is there an easier way?

I'm guessing you are showing the dialog multiple times in the same
scope?

If so try this:

' Dimension the variable once
Dim TheDialog as MyDialogForm

' Then when it's needed instantiate it and use it.
TheDialog = new MyDialogForm()

' The using block will call TheDialog.Dispose() when it exits
Using (TheDialog)
TheDialog.ShowDialog()
' Do whatever here
End Using

Thanks,

Seth Rowe.
 
I'm guessing you are showing the dialog multiple times in the same
scope?

If so try this:

' Dimension the variable once
Dim TheDialog as MyDialogForm

' Then when it's needed instantiate it and use it.
TheDialog = new MyDialogForm()

' The using block will call TheDialog.Dispose() when it exits
Using (TheDialog)
TheDialog.ShowDialog()
' Do whatever here
End Using

Thanks,

Seth Rowe.

Forgive me for being obtuse, but shouldn't the call to the constructor
wipe out the fields?
 
Back
Top