Пример #1
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;
            }
        }