开发者

Custom event on object to change button state

开发者 https://www.devze.com 2023-01-30 04:39 出处:网络
I have 3 buttons on my Data Entry form, OK, APPLY, CANCEL. This form is used to edit a doctor开发者_Go百科\'s details, things like first name, phone # etc...

I have 3 buttons on my Data Entry form, OK, APPLY, CANCEL.

This form is used to edit a doctor开发者_Go百科's details, things like first name, phone # etc...

I have one object doctorObj which at any given time is either empty (a new doctor) or an object pulled from a Linq query.

I deep clone the doctorObj to EditCopyDoctor which is of the same type but used for form editing (so if Cancel is hit, the database do not need to update).

What I want to achieve is observe the EditCopyDoctor for changes against the original doctorObj so

If(doctor.Changed() && doctor.IsNotNew)
{
ApplyButton.Enabled = true;
}
else
{
ApplyButton.Enabled = false;
} 

So I thought writting an event to trigger when something changed on EditCopyDoctor is the best way to do it but I'm not sure how.

I can of course put the ApplyButton.Enabled code in the TextChanged events from the form but I was wondering if there are any quicker ways to do this, I don't really want to do this as there are 10+ textbox and other controls.


Since your "Doctor" type sounds like it's generated by LINQ to SQL/Entities you should find that it already implements the INotifyPropertyChanged interface. Therefore, you should just need to watch the PropertyChanged event and act accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消