0

I have a class that implements IEditableObject and now I'm wondering if it's possible to call BeginEdit() automatically when the source of the binding is updated?

There are two possible scenarios:

  1. Object gets populated via the database. In this case, I don't want to call BeginEdit().
  2. Object gets populated via the input fields by user. In this case, I would like to call the BeginEdit() automatically when the source is updated (I use two-way binding and INotifyPropertyChanged).

I was considering calling BeginEdit() when the property is changed but that wouldn't go along well with the 1st scenario since I don't want BeginEdit() to be called when populating from database.

aks
  • 292
  • 1
  • 5
  • 12
  • Maybe you could implement some kind of IsInDataBaseUpdate property for your object, and when it's set don't hit BeginEdit()? Sorry if it sounds too stupid... Maybe I missed something. – Anvaka Feb 18 '10 at 15:49
  • @Anvaka: I was considering that as well but that's something I tried to avoid because by doing so I wouldn't get what I wanted and it would still be necessary to set the property (in that case I could just call BeginEdit()). I'd like to call BeginEdit() as automatically as possible (if it's possible at all). I'm considering using BindingGroup.BeginEdit(), converter or subclassing Bidning at the moment. – aks Feb 18 '10 at 16:26

1 Answers1

0

You need a way to determine the source of the object population. An enum might do it and then in your PropertyChanged you can check what caused the property to change and based on that, you can call BeginEdit() or not.

Enum PopulateSource
{
   Database = 0,
   User
}

Now when updating from database, set your Enum to PopulateSource.Database. When it changes because the user changed it, you set it to PopulateSource.User. Now you can check in your PropertyChanged what the state of this variable is and so determine whether to call BeginEdit().

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415