StrataFrame Forum

Grandchild Listview

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

By Mike Tomlin - 5/12/2009

I have a child form opened from a listview using the automation features - all works fine. On that child form I have another listview which again opens a form - this form opens and closes OK but I cannot add a new record to the list - it's missing the primary key. If I manually add records to the table they display OK and I can edit them. I think the parent-child relationships are set OK on the BO's.

Does the basic listview automation work when called from a child form or do I need to handle this differently?

Thanks

By Edhy Rijo - 5/12/2009

Hi Mike,



Take a look at this post: http://forum.strataframe.net/FindPost22673.aspx guess it is related to your situation and the way the BOs gets translated to the childform.
By Mike Tomlin - 5/12/2009

Thanks Edhy that's sorted the adding I must have missed that post whilst searching the forum.

The only issue I have left is that if I delete, again using the automation, on deletion the list box is clearing and showing no records. The deletion has happened OK but probably something's amiss with the requerying - do I need to help the automation in this case?

By Edhy Rijo - 5/12/2009

Mike Tomlin (05/12/2009)
...do I need to help the automation in this case?




Yes, the ListView has an event named "ChildFormResults" which you use to make the automation feature to requery the listview. Here is a sample code from one of my listview:





Private Sub lstTransactionItems_ChildFormResults(ByVal sender As System.Object, ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.ListViewChildFormResultsEventArgs) Handles lstTransactionItems.ChildFormResults

If e.Results = Windows.Forms.DialogResult.Cancel Then

Me.BizTransactionItems1.RestoreCurrentDataTableSnapshot(False)

Else

e.Requery = True

End If

End Sub





Also keep in mind that when you delete a record, it may be marked as Deleted only and in that case it will require you to Save() the BO to actually delete the record, there is a property in the listview which controls this feature.



The StrataFlix sample application has several listview used which demonstrate this approach.
By Mike Tomlin - 5/12/2009

I already had in place this...

Private Sub ListView1_ChildFormResults(ByVal sender As System.Object, ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.ListViewChildFormResultsEventArgs) Handles ListView1.ChildFormResults

If e.Results = Windows.Forms.DialogResult.OK Then
'-- Save the BO
Me.Trans_failure_item_BO1.Save()
Else
Me.Trans_failure_item_BO1.RestoreCurrentDataTableSnapshot(False)
End If
'-- Force the listview to requery
Me.ListView1.Requery(CInt(Me.Trans_route_Master_BO1.CurrentRow.Item("route_pk_id")))
End Sub

the listview is filled by the parent primary key and this should force it to requery - it must be working after an add or edit as the display is fine - just the delete goes blank.

By Mike Tomlin - 5/12/2009

Thinking about it this is only called when the child form launched from the listview is involved. In a delete from the listview the child form is not launched.
By Edhy Rijo - 5/12/2009

The Delete should requrery your listview automatically. Also in the ChildFormResults the parameter e.Requery = True will requery the listview based on the parameters you have in the ListPopulating event. Again the StrataFlix uses the latest release of the SF and shows how to handle this with much clear code, even thought what you are doing is OK by passing the parameter to the Requery().
By Trent L. Taylor - 5/13/2009

Edhy is correct in that the StrataFlix shows a number of examples on this and does fully support the most recent version of SF.  Also, if you are allowing the delete to be handled automatically through the ListView, it will remove the record.  The issue that you may be fighting if the deletion is not being reflected further upstream is due to the BO translations.

All translations take place at the time of the Load event.  All code references are updated, however, there are times that you need to manually update the object instance references and this may be one of them.  We do not reflect through all of the objects on the form as this would be very slow using reflection.  So if you override the OnLoad method of the form and manually update the reference on the list, it may resolve your issue.

VB.NET

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
    MyBase.OnLoad(e)
    lstList.BusinessObject = MyBo
End Sub

C#

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    lstList.BusinessObject = MyBo;
}
By Mike Tomlin - 5/13/2009

Thanks for the tips but it didn't sort the delete action not refreshing the listview. For the moment I've opted to handle the delete action in code and that's working OK now and I'll try later to see if I can get it to work with the fully automated options.