StrataFrame Forum

Clarifying expected behaviour when editing related data in a grid

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

By thegwill - 9/30/2007

I have a maintenance form to modify a business object. The form also has a grid containing related child data which is wired up using binding etc.

All seems to work as expected apart from when editing values in the grid (the "child" records) the form's tool strip does not go into "edit mode". How can I get the MFTS to react to the child records in the grid / BO?

Also, for clarification: assuming I can get this working, what would the Undo button do to the child records? Would it undo all changes if I had changed multiple child record values in the grid or just the last row changed? I'm hoping the former...

Thanks in advance

By StrataFrame Team - 10/2/2007

Also, for clarification: assuming I can get this working, what would the Undo button do to the child records? Would it undo all changes if I had changed multiple child record values in the grid or just the last row changed? I'm hoping the former...

It is the former, by default.  However, you will need to change the IncludeInFormUndo property on the form to AllBusinessObjects.  By default, it's only PrimaryBusinessObject, which means that a call to Undo() on the form will only undo the changes to the primary business object.

As for the state of the buttons, there is a new event on the business objects, introduced in 1.6.1, called IsDirtyChanged.  You'll want to handle that event and set the editing state of the business object.  The editing state does not get changed internally unless you manually call the Add() or Edit() methods.  So, something like this will change the state of the toolbar buttons:

Private Sub bo_IsDirtyChanged(ByVal sender As Object, ByVal e As EventArgs) Handles bo.IsDirtyChanged
    If bo.IsDirty Then
        bo.SetEditingState(BusinessEditingState.Editing)
    Else
        bo.SetEditingState(BusinessEditingState.Idle)
    End If
End Sub

By thegwill - 10/5/2007

Thanks Ben

Just to be clear: your example code is handling the event on an instance named "bo" and is also setting the edit state on the same instance - I thought that I would need to handle the event on "childBO" and set the edit state on "parentBO" or am I misunderstanding the purpose of the dirtyness?

By thegwill - 10/5/2007

...and there's no .SetEditingState() method and the .EditingState property is read only

How about I call .Edit() with the same effect:

if (childBO.IsDirty && parentBO.EditingState == BusinessEditingState.Idle)
    parentBO.Edit();

By StrataFrame Team - 10/8/2007

Yep, that would work, too.  I think the SetEditingState() was changed from Friend (internal) to public recently, and it might not be in the latest release, so calling Edit() would work just as well.