Problem with IsDirty

Problem with IsDirty

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


David posted on Wednesday, June 14, 2006

I have an edit form (Windows) with a single business object. Other forms in my application need to know if the object has been edited. To do this I created a read only property that returns MyObject.IsDirty. This works most of the time, unless the user has changed only one text box and has not tabbed off the modified control.

Is there a simple way to handle this situation so that my IsDirty property works reliably?


xal replied on Wednesday, June 14, 2006

Check out this thread: http://forums.lhotka.net/forums/thread/1670.aspx
Andrés

David replied on Wednesday, June 14, 2006

Thanks for the link Andrés. However, keystroke validation presents possible new issues and I wanted to avoid that at present. Fortunately after a bit of research I found another simple solution, and that is to call the form's Validate method just prior to calling the BO's IsDirth property. So this is my form's IsDirty property now:

Public ReadOnly Property IsDirty() As Boolean
  Get
    Me.Validate()
   
Return mBO.IsDirty
  End Get
End Property

Please let me know if anyone is aware of a problem with this approach, otherwise my problem is solved.

Lnk replied on Thursday, June 15, 2006

If you are using .Net 2.0 databinding infrastructure, you can change the "Data Source Update Mode" property to "OnPropertyChanged" for every control on your form (databinding settings for every control). The default value "OnValidation" sends the changes to the datasource when you tab off the control. With "OnPropertyChanged" selected the datasource is updated as you type. This way your object will be always updated with the data shown in your form.

Emilio.

Copyright (c) Marimer LLC