9using System.ComponentModel;
10using System.Collections.Generic;
11using System.Diagnostics;
12using System.Windows.Forms;
27 [DesignerCategory(
"")]
28 [ProvideProperty(
"ReadValuesOnChange", typeof(BindingSource))]
32 private readonly Dictionary<BindingSource, bool> _sources =
new Dictionary<BindingSource, bool>();
46 InitializeComponent();
55 InitializeComponent();
59 #region Designer Functionality
63 private System.ComponentModel.IContainer components =
null;
68 protected override void Dispose(
bool disposing)
70 if (disposing && (components !=
null))
74 base.Dispose(disposing);
76 #region Component Designer generated code
81 private void InitializeComponent()
83 components =
new System.ComponentModel.Container();
87 #region Public Methods
96 return (extendee is BindingSource);
107 if (_sources.TryGetValue(source, out result))
121 BindingSource source,
bool value)
123 _sources[source] = value;
124 if (!_isInitialising)
126 RegisterControlEvents(source, value);
138#if NETSTANDARD2_0 || NET5_0
139 [System.ComponentModel.DataAnnotations.ScaffoldColumn(
false)]
141 public ContainerControl
Host {
get;
set; }
147 [DefaultValue(
false)]
152 #region Private Methods
159 private void RegisterControlEvents(ICurrencyManagerProvider container,
bool register)
161 var currencyManager = container.CurrencyManager;
165 currencyManager.Bindings.CollectionChanged += Bindings_CollectionChanged;
166 currencyManager.Bindings.CollectionChanging += Bindings_CollectionChanging;
171 currencyManager.Bindings.CollectionChanged -= Bindings_CollectionChanged;
172 currencyManager.Bindings.CollectionChanging -= Bindings_CollectionChanging;
175 RegisterBindingEvents(currencyManager.Bindings,
register);
184 private void RegisterBindingEvents(BindingsCollection source,
bool register)
186 foreach (Binding binding
in source)
188 RegisterBindingEvent(binding,
register);
196 private void RegisterBindingEvent(Binding binding,
bool register)
200 binding.BindingComplete += Control_BindingComplete;
204 binding.BindingComplete -= Control_BindingComplete;
208 #region Event Methods
217 private void Bindings_CollectionChanging(
object sender, CollectionChangeEventArgs e)
221 case CollectionChangeAction.Refresh:
223 RegisterBindingEvents((BindingsCollection)sender,
false);
225 case CollectionChangeAction.Add:
227 RegisterBindingEvent((Binding)e.Element,
false);
229 case CollectionChangeAction.Remove:
231 RegisterBindingEvent((Binding)e.Element,
false);
243 private void Bindings_CollectionChanged(
object sender, CollectionChangeEventArgs e)
247 case CollectionChangeAction.Refresh:
249 RegisterBindingEvents((BindingsCollection)sender,
true);
251 case CollectionChangeAction.Add:
253 RegisterBindingEvent((Binding)e.Element,
true);
255 case CollectionChangeAction.Remove:
269 private void Control_BindingComplete(
object sender, BindingCompleteEventArgs e)
271 switch (e.BindingCompleteState)
273 case BindingCompleteState.Exception:
275 && e.Binding.DataSource is BindingSource
278 e.Binding.ReadValue();
282 BindingError(
this,
new BindingErrorEventArgs(e.Binding, e.Exception));
286 if ((e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate)
287 && e.Binding.DataSource is BindingSource
290 e.Binding.ReadValue();
297 #region ISupportInitialize Interface
298 private bool _isInitialising =
false;
302 void ISupportInitialize.BeginInit()
304 _isInitialising =
true;
310 void ISupportInitialize.EndInit()
312 _isInitialising =
false;
313 foreach (var source
in _sources)
316 RegisterControlEvents(source.Key,
true);
333 #region BindingErrorEventArgs Class
341 #region Property Fields
344 private Binding _binding =
null;
355 get {
return (_exception); }
363 get {
return (_binding); }
378 _exception = exception;
BindingErrorEventArgs defines the event arguments for reporting a data binding error due to a excepti...
BindingErrorEventArgs(Binding binding, Exception exception)
Constructor creates a new BindingErrorEventArgs object instance using the information specified.
Binding Binding
Binding gets the binding that caused the exception.
Exception Exception
Exception gets the exception that caused the binding error.
BindingSourceRefresh contains functionality for refreshing the data bound to controls on Host as well...
BindingSourceRefresh()
Constructor creates a new BindingSourceRefresh component then initialises all the different sub compo...
override void Dispose(bool disposing)
Clean up any resources being used.
void SetReadValuesOnChange(BindingSource source, bool value)
SetReadValuesOnChange() sets the value of the custom ReadValuesOnChange extender property added to ex...
BindingSourceRefresh(IContainer container)
Constructor creates a new BindingSourceRefresh component, adds the component to the container supplie...
bool GetReadValuesOnChange(BindingSource source)
GetReadValuesOnChange() gets the value of the custom ReadValuesOnChange extender property added to ex...
bool CanExtend(object extendee)
CanExtend() returns true if extendee is a binding source.
bool RefreshOnException
Forces the binding to re-read after an exception is thrown when changing the binding value
ContainerControl Host
Not in use - kept for backward compatibility
BindingErrorEventHandler BindingError
BindingError event is raised when a data binding error occurs due to a exception.
delegate void BindingErrorEventHandler(object sender, BindingErrorEventArgs e)
BindingErrorEventHandler delegates is the event handling definition for handling data binding errors ...