StrataFrame Forum

Notify to show error

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

By Chan - 9/16/2007

Hi,

I would like to raise "exception" in Property Setter method. For example, upon user specify value to textbox and updated to field property, my program will check for some logic, if not valid, I want to show error provider icon immediately instead of waiting Save().



I tried to add broken rules, but it doesn't reflect the UI.



How to raise the "event" so that error provider icon will be shown?



Thank you
By Trent L. Taylor - 9/17/2007

You would have to handle an event or add the logic to the Set method of the property.  This may be a good place for you to use the INotifyPropertyChanged event.

Public Class MyClass
    Implements System.ComponentModel.INotifyPropertyChanged

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged


    Public Property MyProperty As String
        Get
            Return _MyProperty
        End Get
        Set(Byval value as String)
            _MyProperty = value
            Raiseevent PropertyChanged(Me,New System.ComponentModel.PropertyChangedEventArgs("MyProperty"))
        End Set
    End Property

End Class

There are some other ways to go about it as well, but you will have to take action on the setting of the property.  If you want to use the BO mapper to do this for you, then use the PropertyChanging or PropertyChanged events.

By StrataFrame Team - 9/18/2007

Most grids have a DataError event that will be raised when an exception occurs.  The grid will trap the exception and raise the event and pass the exception through the event args.  This would allow you to show a message box or set the text on a label somewhere that would indicate the error to the user.  However, as I mentioned in your other post about this similar matter, you'll need to add the broken rules to the BBS.BusinessObject reference for the ErrorProvider to pick up the error and display it.