Пример #1
0
 private void BindTarget(bool bind)
 {
     if (bind)
     {
         if (IsBinding)
         {
             if (propInfo != null && control != null)
             {
                 EventHandler handler = new EventHandler(this.Target_PropertyChanged);
                 propInfo.AddValueChanged(control, handler);
             }
             if (validateInfo != null)
             {
                 CancelEventHandler handler = new CancelEventHandler(this.Target_Validate);
                 validateInfo.AddEventHandler(control, handler);
             }
         }
     }
     else
     {
         if (propInfo != null && control != null)
         {
             EventHandler handler = new EventHandler(this.Target_PropertyChanged);
             propInfo.RemoveValueChanged(control, handler);
         }
         if (validateInfo != null)
         {
             CancelEventHandler handler = new CancelEventHandler(this.Target_Validate);
             validateInfo.RemoveEventHandler(control, handler);
         }
     }
 }
Пример #2
0
 internal PropertyManager(Object dataSource, string propName) : this(dataSource) {
     propInfo = TypeDescriptor.GetProperties(dataSource).Find(propName, true);
     if (propInfo == null)
     {
         throw new ArgumentException(SR.GetString(SR.PropertyManagerPropDoesNotExist, propName, dataSource.ToString()));
     }
     propInfo.AddValueChanged(dataSource, new EventHandler(PropertyChanged));
 }
Пример #3
0
        internal void CheckBinding()
        {
            // At design time, don't check anything.
            //
            if (owner != null &&
                owner.BindableComponent != null &&
                owner.ControlAtDesignTime())
            {
                return;
            }

            // force Column to throw if it's currently a bad column.
            //DataColumn tempColumn = this.Column;

            // remove propertyChangedNotification when this binding is deleted
            if (this.owner.BindingManagerBase != null &&
                this.fieldInfo != null &&
                this.owner.BindingManagerBase.IsBinding &&
                !(this.owner.BindingManagerBase is CurrencyManager))
            {
                fieldInfo.RemoveValueChanged(owner.BindingManagerBase.Current, new EventHandler(PropValueChanged));
            }

            if (owner != null &&
                owner.BindingManagerBase != null &&
                owner.BindableComponent != null &&
                owner.ComponentCreated &&
                this.IsDataSourceInitialized)
            {
                string dataField = dataMember.BindingField;

                fieldInfo = owner.BindingManagerBase.GetItemProperties().Find(dataField, true);
                if (owner.BindingManagerBase.DataSource != null && fieldInfo == null && dataField.Length > 0)
                {
                    throw new ArgumentException(SR.GetString(SR.ListBindingBindField, dataField), "dataMember");
                }

                // Do not add propertyChange notification if
                // the fieldInfo is null
                //
                // we add an event handler to the dataSource in the BindingManagerBase because
                // if the binding is of the form (Control, ControlProperty, DataSource, Property1.Property2.Property3)
                // then we want to get notification from Current.Property1.Property2 and not from DataSource
                // when we get the backEnd notification we push the new value into the Control's property
                //
                if (fieldInfo != null &&
                    owner.BindingManagerBase.IsBinding &&
                    !(this.owner.BindingManagerBase is CurrencyManager))
                {
                    fieldInfo.AddValueChanged(this.owner.BindingManagerBase.Current, new EventHandler(PropValueChanged));
                }
            }
            else
            {
                fieldInfo = null;
            }
        }
Пример #4
0
        internal override void SetDataSource(Object dataSource)
        {
            if (this.dataSource != null && !String.IsNullOrEmpty(this.propName))
            {
                propInfo.RemoveValueChanged(this.dataSource, new EventHandler(PropertyChanged));
                propInfo = null;
            }

            this.dataSource = dataSource;

            if (this.dataSource != null && !String.IsNullOrEmpty(this.propName))
            {
                propInfo = TypeDescriptor.GetProperties(dataSource).Find(propName, true);
                if (propInfo == null)
                {
                    throw new ArgumentException(string.Format(SR.PropertyManagerPropDoesNotExist, propName, dataSource.ToString()));
                }
                propInfo.AddValueChanged(dataSource, new EventHandler(PropertyChanged));
            }
        }
Пример #5
0
        private protected override void SetDataSource(object dataSource)
        {
            if (_dataSource != null && !string.IsNullOrEmpty(_propName))
            {
                _propInfo.RemoveValueChanged(_dataSource, new EventHandler(PropertyChanged));
                _propInfo = null;
            }

            _dataSource = dataSource;

            if (_dataSource != null && !string.IsNullOrEmpty(_propName))
            {
                _propInfo = TypeDescriptor.GetProperties(dataSource).Find(_propName, true);
                if (_propInfo is null)
                {
                    throw new ArgumentException(string.Format(SR.PropertyManagerPropDoesNotExist, _propName, dataSource.ToString()));
                }

                _propInfo.AddValueChanged(dataSource, new EventHandler(PropertyChanged));
            }
        }