Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting changes in children
Message
From
19/10/2004 18:12:59
Max Fillmore
Essential Skills, Inc.
Lenexa, Kansas, United States
 
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00951764
Message ID:
00952831
Views:
14
Thanks Kevin,

That was a big help although I can't get it to work the way you suggested.

Unfortunately my project is in VB.NET so I converted your code to VB and put it in a subclass of mmBusinessForm like this:
    Public Class ABusinessForm
        Inherits OakLeaf.MM.Main.Windows.Forms.mmBusinessForm

        Public Shadows Sub NavigateData(ByVal navPosition As mmNavigate, 
Optional ByVal raiseEvents As Boolean = False)
            ...
        End Sub
This didn't quite work for me. At the points in my form where I called NavigateData() the shadow subroutine above was called. However when I click the toolbar navigation buttons on the main form it calls the original code in mmBusinessForm.

Big question: What do I have to do to integrate your code into mmBusinessForm directly and recompile/rebuild? This would be my preference.

If that's not possible how can I override the navigation toolbar on the main form to call by ABusinessForm version of NavigateData() ?

I was already working with code like the "Check for changes" block in my HookPreNavigate() and found another consideration which you should take into account. My business objects all have AutoIncrementCustom = True. Thus when a new row is added to the primary bizobj it gets changed before the user even sees the new blank row in the form. If the user clicks btnCancel or btnDelete they have already had to answer the prompt. Then when they get to my HookPreNavigate they would have to answer the AskSaveChanges. To avoid this I added a Protected boolean to my ABusinessForm:
Protected IgnoreIsChanged As Boolean = False

Also these two hook overrides:
        Protected Overloads Overrides Function HookPreCancel(ByVal bizObj 
As OakLeaf.MM.Main.Business.mmBusinessObject, ByVal tableName As String) As Boolean
            Me.IgnoreIsChanged = True
            Return MyBase.HookPreCancel(bizObj, tableName)
        End Function

        Protected Overloads Overrides Function HookPreDelete(ByVal drView 
As System.Data.DataRowView) As Boolean
            Me.IgnoreIsChanged = True
            Return MyBase.HookPreDelete(drView)
        End Function

So now the bottom of HookPreNavigate() looks like this:

            Dim RetVal As Boolean = True
            Dim FocusOnSaveControl As Control
            Dim FocusOnCancelControl As Control
            Dim IgnoreIsChanged As Boolean = Me.IgnoreIsChanged

            If Me.IgnoreIsChanged Then
                Me.IgnoreIsChanged = False
            End If

            If Me.PrimaryBizObj.IsChanged Then
                If Not IgnoreIsChanged Then
                    FocusOnSaveControl = Me.FocusOnSaveControl
                    Me.FocusOnSaveControl = Nothing
                    FocusOnCancelControl = Me.FocusOnCancelControl
                    Me.FocusOnCancelControl = Nothing

                    If AskSaveChanges(Me.PrimaryBizObj) = DialogResult.Cancel Then
                            RetVal = False
                    End If

                    Me.FocusOnSaveControl = FocusOnSaveControl
                    Me.FocusOnCancelControl = FocusOnCancelControl
                End If
            End If

            Return RetVal And MyBase.HookPreNavigate()
This cures everything except btnNew. When btnNew is clicked it eventually executes:
DataRow row = BusinessForm.NewRow(BizObj, TableName);
This causes the new row to be the PrimaryBizObj.Datarow. However if I don't do a form level navigate the bound controls on my form are all populated with the data from the previous datarow when I begin to edit. I get around this with:
        Private Sub btnNew_Click(ByVal sender As System.Object, 
ByVal e As System.EventArgs) Handles btnNew.Click
            If Me.btnNew.Result Then
                ' Ignore the IsChanged property in ABusinessForm.NavigateData
                Me.IgnoreIsChanged = True

                ' Navigate to the new record
                Me.NavigateData(mmNavigate.Last, True)
            End If
        End Sub
Notice that I have to do Me.IgnoreIsChanged = True because I am sitting on the new record which has primary key = -1 and is therefore changed. I feel like I'm writing kluge code here. How can this be cleaned up in the framework?

Thanks,
Max...
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform