Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
926 views
in Technique[技术] by (71.8m points)

datatable - WinForms: Why does databinding break if adding an event with "Changed" suffix?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you are defining RelatedProgramsChanged, you should also fire that event when the property value changes. You have not shown enough code to pinpoint the failure point in your implementation.

The PropertyNameChanged event was the way to signal a change before the introduction of the INotifyPropertyChanged Interface. For more information see: Property-Changed Events.

From the Remarks section of INotifyPropertyChanged:

For change notification to occur in a binding between a bound client and a data source, your bound type should either:

  • Implement the INotifyPropertyChanged interface (preferred).

  • Provide a change event for each property of the bound type.

Do not do both.

This event along with the ShouldSerializePropertyName and ResetPropertyName (see: Defining Default Values with the ShouldSerialize and Reset Methods) methods are retrieved by the property descriptor used by the WinForm binding mechanism. You can inspect the propery descriptor code at ReflectPropertyDescriptor and read the comments to learn more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...