StrataFrame Forum

The Navigating event and Adding a record

http://forum.strataframe.net/Topic7720.aspx

By Greg McGuffey - 3/26/2007

I am reacting to the Navigating event of a BO, to see if it is dirty and then allow the user to handle it if it is dirty. It appears to be raised AFTER the new row is added but before it is navigated to. The code I'm using in the Navigating event is:



If e.BusinessObject.IsDirty Then

' Confirm message

'...setup MessageItem so we can use MessageForm() to get result



Select Case MessageForm.ShowMessage(msgItem)

Case MessageFunctionType.Yes

e.BusinessObject.Save()

Case MessageFunctionType.No

e.BusinessObject.Undo(CurrentRowOnly)

Case MessageFunctionType.Cancel

' Cancel nav and any thing else to reset UI

e.Cancel = True

End Select







The problem is that when I click a button that calls the Add() method of the BO. This then calls the Navigating event handler (at some point) after the new record is added (which I guess makes sense). If the editing state of the BO is idle (not editing anything when Add() was called), the BO is dirty already. This then blows up because there is nothing to save or undo and canceling cancels the navigation to the new record! I'm not sure how to handle the case of a new record. Ideas?



I'm doing it this way because I have a listbox that allows the user to view all available records and navigate via the listbox.