Capturing child saved events in Editable Root List

Capturing child saved events in Editable Root List

Old forum URL: forums.lhotka.net/forums/t/7522.aspx


Tom_W posted on Friday, August 28, 2009

Hi All

Our current project is MDI Winforms and I'd like to display a '*' on a form's tab if the record is dirty and an '!' if the record is invalid.

I have written a bit of code as follows;

Public Class StockItemEditControl
    Dim WithEvents _stockItemList As StockItemEditList

    Public Sub New()
        InitializeComponent()

        Me.FormCaption = "Stock Items"

        _stockItemList = StockItemEditList.GetStockItemEditList()
        StockItemEditBindingSource.DataSource = _stockItemList

        'AddHandler _stockItemList.ChildChanged, AddressOf DirtyCaption
        'Dim ieo As System.ComponentModel.INotifyPropertyChanged = DirectCast(_stockItemList, System.ComponentModel.INotifyPropertyChanged)
        'AddHandler ieo.PropertyChanged, AddressOf DirtyCaption
        AddHandler _stockItemList.AddingNew, AddressOf AddingNew_Handler
        AddHandler _stockItemList.ChildChanged, AddressOf ChildChanged_Handler
        AddHandler _stockItemList.ListChanged, AddressOf ListChanged_Handler
        AddHandler _stockItemList.RemovingItem, AddressOf RemovingItem_Handler
        AddHandler _stockItemList.Saved, AddressOf Saved_Handler
    End Sub

    Public Sub ChildChanged_Handler(ByVal sender As Object, ByVal e As ChildChangedEventArgs)
        ResetDirtyCaption()
    End Sub

    Public Sub AddingNew_Handler(ByVal sender As Object, ByVal e As AddingNewEventArgs)
        ResetDirtyCaption()
    End Sub

    Public Sub ListChanged_Handler(ByVal sender As Object, ByVal e As ListChangedEventArgs)
        ResetDirtyCaption()
    End Sub

    Public Sub RemovingItem_Handler(ByVal sender As Object, ByVal e As RemovingItemEventArgs)
        ResetDirtyCaption()
    End Sub

    Public Sub Saved_Handler(ByVal sender As Object, ByVal e As SavedEventArgs)
        ResetDirtyCaption()
    End Sub


    Public Sub ResetDirtyCaption()
        If _stockItemList.IsDirty Then
            If _stockItemList.IsValid Then
                'Object is dirty, but OK to save
                FormCaption = "Stock Items *"
            Else
                'Object is dirty and invalid
                FormCaption = "Stock Items !"
            End If
        Else
            FormCaption = "Stock Items*"
        End If
    End Sub


The above is all working great, except that BLB's Saved event doesn't always seem to fire.  I'm guessing it isn't necessarily thrown if one of it's child objects is saved?

A possibly related point here is that my child object's insert and update methods do not take the parent object as a parameter, i.e. in the child StockItemEdit :

    private void Child_Insert()
    {

    private void Child_Update()
    {

Could that be the cause?  I guess really my question is should BLB's Saved event fire every time one of it's children fires or is that not what its for?



Copyright (c) Marimer LLC