I have a problem with my code...
VB Code:
Public Class frmViewEditBoundary Inherits System.Windows.Forms.Form 'some code omitted for clarity 'constructor Public Sub New(ByVal data As Boundary) MyBase.New() InitializeComponent() itsBoundary = data End Sub Public Shadows Function ShowDialog(ByRef owner As IWin32Window) As Boundary MyBase.ShowDialog(owner) 'call the base class version and ignore its return value Return DialogResult 'return our own data End Function Public Shadows Property DialogResult() As Boundary Get Return itsDialogResult End Get Set(ByVal Value As Boundary) itsDialogResult = Value End Set End Property 'other code omitted for clarity Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click DialogResult = Nothing Me.Close() End Sub Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click DialogResult = itsBoundary Me.Close() End Sub End Class
What it should do:
A Boundary object is passed in when declaring a NEW frmViewEditBoundary instance. This boundary's data is examined and displayed in the form's controls. This part works OK. But when the user has finished viewing or editing the data he clicks either OK or CANCEL to close the form.
If OK is clicked then the boundary object is returned via the DialogResult property that I have shadowed to use class Boundary as its data type. It should be returned regardless of any changes made.
If CANCEL is clicked then the value NOTHING is passed back instead.
However, the problem is that no matter which button I hit the boundary is passed back. Why is this? The code for the buttons is right at the bottom of the class block above.
Have I shadowed the 2 things properly (DialogResult and ShowDialog())?
Any ideas?
Thanks,
Adam.




Reply With Quote