예제 #1
0
        /// <summary>
        /// Sets the Focus to a databound control within a given Form or a UserControl by
        /// specifying the column to which it is bound.
        ///
        /// </summary>
        /// <param name="AContainerControl">Either a Form or a UserControl.</param>
        /// <param name="ABindingManagerBase">BindingManagerBase where the data binding
        /// information is stored</param>
        /// <param name="AColumnName">Name of the column whose databound control should get the
        /// focus.</param>
        /// <returns>Name of the control, or empty string if not found.
        /// </returns>
        public static String SetFocusOnDataBoundControlInternal(ContainerControl AContainerControl,
            BindingManagerBase ABindingManagerBase,
            String AColumnName)
        {
            Int16 Counter1;
            String ControlName;

            ControlName = "";

            // MessageBox.Show('SetFocusOnDataBoundControlInternal: looking for control that belongs to DataColumn ' + AColumnName + '...');
            // MessageBox.Show('Number of Bindings: ' + ABindingManagerBase.Bindings.Count.ToString);
            for (Counter1 = 0; Counter1 <= ABindingManagerBase.Bindings.Count - 1; Counter1 += 1)
            {
                // MessageBox.Show('ABindingManagerBase.Bindings.Item[Counter1].BindingMemberInfo.BindingField: ' + ABindingManagerBase.Bindings.Item[Counter1].BindingMemberInfo.BindingField);
                if (ABindingManagerBase.Bindings[Counter1].BindingMemberInfo.BindingField == AColumnName)
                {
                    // MessageBox.Show('BmbPartnerLocation.Bindings.Item[Counter1].Control.Name: ' + ABindingManagerBase.Bindings.Item[Counter1].Control.Name);
                    ControlName = TFocusing.SetFocusOnControlInFormOrUserControl(AContainerControl,
                        ABindingManagerBase.Bindings[Counter1].Control.Name);
                    break;
                }
            }

            return ControlName;
        }
		public RelatedCurrencyManager (BindingManagerBase parent, PropertyDescriptor prop_desc)
			: base (prop_desc.GetValue (parent.Current))
		{
			this.parent = parent;
			this.prop_desc = prop_desc;

			parent.PositionChanged += new EventHandler (parent_PositionChanged);
		}
 private static object GetCurrentOrNull(BindingManagerBase parentManager)
 {
     if ((parentManager.Position < 0) || (parentManager.Position >= parentManager.Count))
     {
         return null;
     }
     return parentManager.Current;
 }
예제 #4
0
        private DataRow GetRow()
        {
            System.Windows.Forms.BindingManagerBase bm = this.BindingContext[this.dsInitializeData, "Student"];
            DataRowView drvx = (System.Data.DataRowView)bm.Current;

            return(drvx.Row);

            throw new NotImplementedException();
        }
        private void WireParentManager(BindingManagerBase bmb) {
            if (bmb != null) {
                bmb.CurrentItemChanged += new EventHandler(ParentManager_CurrentItemChanged);

                if (bmb is CurrencyManager) {
                    (bmb as CurrencyManager).MetaDataChanged += new EventHandler(ParentManager_MetaDataChanged);
                }
            }
        }
		public RelatedPropertyManager (BindingManagerBase parent, string property_name)
		{
			this.parent = parent;
			this.property_name = property_name;

			if (parent.Position != -1)
				SetDataSource (parent.Current);
			parent.PositionChanged += new EventHandler (parent_PositionChanged);
		}
예제 #7
0
 // Add an entry to this collection.
 protected internal void Add
     (Object dataSource, BindingManagerBase listManager)
 {
     AddCore(dataSource, listManager);
                 #if CONFIG_COMPONENT_MODEL
     OnCollectionChanged
         (new CollectionChangeEventArgs
             (CollectionChangeAction.Add, dataSource));
                 #endif
 }
예제 #8
0
        public RelatedPropertyManager(BindingManagerBase parent, string property_name)
        {
            this.parent        = parent;
            this.property_name = property_name;

            if (parent.Position != -1)
            {
                SetDataSource(parent.Current);
            }
            parent.PositionChanged += new EventHandler(parent_PositionChanged);
        }
 public FRM_CATEGORIES()
 {
     InitializeComponent();
     da = new SqlDataAdapter("SELECT ID_CAT as 'رقم',DESCRIPTION_CAT as 'الصنف' FROM CATEGORIES", sqlcon);
     da.Fill(dt);
     dataGridView1.DataSource = dt;
     txtID.DataBindings.Add("text", dt, "رقم");
     txtDes.DataBindings.Add("text", dt, "الصنف");
     bmb = this.BindingContext[dt];
     lblPosition.Text = (bmb.Position + 1) + " / " + bmb.Count;
 }
 private void WireParentManager(BindingManagerBase bmb)
 {
     if (bmb != null)
     {
         bmb.CurrentItemChanged += new EventHandler(this.ParentManager_CurrentItemChanged);
         if (bmb is CurrencyManager)
         {
             (bmb as CurrencyManager).MetaDataChanged += new EventHandler(this.ParentManager_MetaDataChanged);
         }
     }
 }
 private void Bind(BindingManagerBase parentManager, string dataField) {
     Debug.Assert(parentManager != null, "How could this be a null parentManager.");
     this.parentManager = parentManager;
     this.dataField = dataField;
     this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true);
     if (fieldInfo == null)
         throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataField));
     // this.finalType = fieldInfo.PropertyType;
     parentManager.CurrentItemChanged += new EventHandler(ParentManager_CurrentItemChanged);
     Refresh();
 }
 private void Bind(BindingManagerBase parentManager, string dataField)
 {
     this.parentManager = parentManager;
     this.dataField = dataField;
     this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true);
     if (this.fieldInfo == null)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("RelatedListManagerChild", new object[] { dataField }));
     }
     parentManager.CurrentItemChanged += new EventHandler(this.ParentManager_CurrentItemChanged);
     this.Refresh();
 }
예제 #13
0
 private void Bind(BindingManagerBase parentManager, string dataField)
 {
     this.parentManager = parentManager;
     this.dataField     = dataField;
     this.fieldInfo     = parentManager.GetItemProperties().Find(dataField, true);
     if (this.fieldInfo == null)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("RelatedListManagerChild", new object[] { dataField }));
     }
     parentManager.CurrentItemChanged += new EventHandler(this.ParentManager_CurrentItemChanged);
     this.Refresh();
 }
예제 #14
0
 protected virtual void AddCore(object dataSource, BindingManagerBase listManager)
 {
     if (dataSource == null)
     {
         throw new ArgumentNullException("dataSource");
     }
     if (listManager == null)
     {
         throw new ArgumentNullException("listManager");
     }
     this.listManagers[this.GetKey(dataSource, "")] = new WeakReference(listManager, false);
 }
        private void UnwireParentManager(BindingManagerBase bmb)
        {
            if (bmb is not null)
            {
                bmb.CurrentItemChanged -= new EventHandler(ParentManager_CurrentItemChanged);

                if (bmb is CurrencyManager)
                {
                    (bmb as CurrencyManager).MetaDataChanged -= new EventHandler(ParentManager_MetaDataChanged);
                }
            }
        }
 protected virtual void AddCore(object dataSource, BindingManagerBase listManager)
 {
     if (dataSource == null)
     {
         throw new ArgumentNullException("dataSource");
     }
     if (listManager == null)
     {
         throw new ArgumentNullException("listManager");
     }
     this.listManagers[this.GetKey(dataSource, "")] = new WeakReference(listManager, false);
 }
예제 #17
0
 protected virtual void AddCore
     (Object dataSource, BindingManagerBase listManager)
 {
     if (dataSource == null)
     {
         throw new ArgumentNullException("dataSource");
     }
     if (listManager == null)
     {
         throw new ArgumentNullException("listManager");
     }
     list[new BindingHashEntry(dataSource, String.Empty)] =
         listManager;
 }
 internal RelatedCurrencyManager(BindingManagerBase parentManager, string dataField) : base(null)
 {
     Debug.Assert(parentManager != null, "How could this be a null parentManager.");
     this.parentManager = parentManager;
     this.dataField     = dataField;
     this.fieldInfo     = parentManager.GetItemProperties().Find(dataField, true);
     if (fieldInfo == null || !typeof(IList).IsAssignableFrom(fieldInfo.PropertyType))
     {
         throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataField));
     }
     this.finalType = fieldInfo.PropertyType;
     parentManager.CurrentChanged += new EventHandler(ParentManager_CurrentChanged);
     ParentManager_CurrentChanged(parentManager, EventArgs.Empty);
 }
예제 #19
0
        private void Bind(BindingManagerBase parentManager, string dataField)
        {
            Debug.Assert(parentManager != null, "How could this be a null parentManager.");
            this.parentManager = parentManager;
            this.dataField     = dataField;
            fieldInfo          = parentManager.GetItemProperties().Find(dataField, true);
            if (fieldInfo == null)
            {
                throw new ArgumentException(string.Format(SR.RelatedListManagerChild, dataField));
            }

            parentManager.CurrentItemChanged += new EventHandler(ParentManager_CurrentItemChanged);
            Refresh();
        }
 internal void Bind(BindingManagerBase parentManager, string dataField)
 {
     this.UnwireParentManager(this.parentManager);
     this.parentManager = parentManager;
     this.dataField     = dataField;
     this.fieldInfo     = parentManager.GetItemProperties().Find(dataField, true);
     if ((this.fieldInfo == null) || !typeof(IList).IsAssignableFrom(this.fieldInfo.PropertyType))
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("RelatedListManagerChild", new object[] { dataField }));
     }
     base.finalType = this.fieldInfo.PropertyType;
     this.WireParentManager(this.parentManager);
     this.ParentManager_CurrentItemChanged(parentManager, EventArgs.Empty);
 }
 internal void Bind(BindingManagerBase parentManager, string dataField)
 {
     this.UnwireParentManager(this.parentManager);
     this.parentManager = parentManager;
     this.dataField = dataField;
     this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true);
     if ((this.fieldInfo == null) || !typeof(IList).IsAssignableFrom(this.fieldInfo.PropertyType))
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("RelatedListManagerChild", new object[] { dataField }));
     }
     base.finalType = this.fieldInfo.PropertyType;
     this.WireParentManager(this.parentManager);
     this.ParentManager_CurrentItemChanged(parentManager, EventArgs.Empty);
 }
예제 #22
0
        /// <include file='doc\BindingContext.uex' path='docs/doc[@for="BindingContext.AddCore"]/*' />
        /// <devdoc>
        /// </devdoc>
        protected virtual void AddCore(object dataSource, BindingManagerBase listManager)
        {
            /* !!THIS METHOD IS OBSOLETE AND UNUSED!! */
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }
            if (listManager == null)
            {
                throw new ArgumentNullException("listManager");
            }

            // listManagers[dataSource] = listManager;
            listManagers[GetKey(dataSource, "")] = new WeakReference(listManager, false);
        }
예제 #23
0
        protected virtual void AddCore(object dataSource, BindingManagerBase listManager)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }
            if (listManager == null)
            {
                throw new ArgumentNullException("listManager");
            }

            HashKey key = new HashKey(dataSource, String.Empty);

            managers [key] = listManager;
        }
예제 #24
0
		private void MultipleControlBinding_Load(object sender, EventArgs e)
		{
			DataTable dt = Program.StoreDB.GetProducts();

			cboModelName.DataSource = dt;
			cboModelName.DisplayMember = "ModelName";

			lblModelNumber.DataBindings.Add("Text",	dt, "ModelNumber");
			lblUnitCost.DataBindings.Add("Text", dt, "UnitCost", true, DataSourceUpdateMode.OnPropertyChanged, 0, "C");
			lblDescription.DataBindings.Add("Text",	dt, "Description");
			
			// Keep track of the binding context.
			storeBinding = this.BindingContext[dt];

			storeBinding.PositionChanged += new EventHandler(Binding_PositionChanged);
		}
예제 #25
0
        internal void SetBindingManagerBase(BindingManagerBase lManager)
        {
            if (bindingManager == lManager)
            {
                return;
            }

            // remove notification from the backEnd
            if (bindingManager != null && fieldInfo != null && bindingManager.IsBinding && !(bindingManager is CurrencyManager))
            {
                fieldInfo.RemoveValueChanged(bindingManager.Current, new EventHandler(PropValueChanged));
                fieldInfo = null;
            }

            this.bindingManager = lManager;
            CheckBinding();
        }
예제 #26
0
        internal void SetListManager(BindingManagerBase bindingManagerBase)
        {
            if (this.bindingManagerBase is CurrencyManager)
            {
                ((CurrencyManager)this.bindingManagerBase).MetaDataChanged -= new EventHandler(binding_MetaDataChanged);
            }

            this.bindingManagerBase = bindingManagerBase;

            if (this.bindingManagerBase is CurrencyManager)
            {
                ((CurrencyManager)this.bindingManagerBase).MetaDataChanged += new EventHandler(binding_MetaDataChanged);
            }

            this.BindToObject.SetBindingManagerBase(bindingManagerBase);
            CheckBinding();
        }
예제 #27
0
        internal void SetListManager(BindingManagerBase newBindingManagerBase)
        {
            if (_bindingManagerBase is CurrencyManager oldCurrencyManagEr)
            {
                oldCurrencyManagEr.MetaDataChanged -= new EventHandler(binding_MetaDataChanged);
            }

            _bindingManagerBase = newBindingManagerBase;

            if (newBindingManagerBase is CurrencyManager newCurrencyManager)
            {
                newCurrencyManager.MetaDataChanged += new EventHandler(binding_MetaDataChanged);
            }

            _bindToObject.SetBindingManagerBase(newBindingManagerBase);
            CheckBinding();
        }
예제 #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            string Command = sqlcom.CommandText;

            sqlcom.CommandText = "update reports set score=" + textBox3.Text +
                " where sno in ( select sno from students where sname='" +
                textBox1.Text + "') and cno in ( " + "select cno from courses where cname='"
                + textBox2.Text + "')";

            sqlcon.Open();
            sqlcom.ExecuteNonQuery();
            sqlcon.Close();

            /////////////////////////////////
            BMB = this.BindingContext[dv];
            int index = BMB.Position;

            ////////////////////////////////
            ds.Reset();
            sqlcom.CommandText = Command;
            sqlda.SelectCommand = sqlcom;
            sqlcon.Open();
            sqlda.Fill(ds);
            sqlcon.Close();

            string filter = dv.RowFilter;
            dv = ds.Tables[0].DefaultView;
            dv.RowFilter = filter;
            dataGridView1.DataSource = dv;
            //////////////////////////////////

            BMB = this.BindingContext[dv];
            BMB.Position = index;
            ///////////////////////////////

            textBox1.DataBindings.Clear();
            textBox1.DataBindings.Add(new Binding("Text", dv, "学生"));
            textBox2.DataBindings.Clear();
            textBox2.DataBindings.Add(new Binding("Text", dv, "课程"));
            textBox3.DataBindings.Clear();
            textBox3.DataBindings.Add(new Binding("Text", dv, "成绩"));

            statusBar1.Text = "成绩更新成功";
            Thread.Sleep(1000);
            statusBar1.Text = "状态栏 无消息";
        }
예제 #29
0
		private void MasterDetail_Load(object sender, EventArgs e)
		{
			ds = Program.StoreDB.GetCategoriesAndProducts();

			// Bind the lists to different tables.
			lstCategory.DataSource = ds.Tables["Categories"];
			lstCategory.DisplayMember = "CategoryName";

			lstProduct.DataSource = ds.Tables["Products"];
			lstProduct.DisplayMember = "ModelName";

			// Track the binding context and handle position changing.
			categoryBinding = this.BindingContext[ds.Tables["Categories"]];
			categoryBinding.PositionChanged += new EventHandler(Binding_PositionChanged);

			// Update child table at startup.
			UpdateProducts();
		}
예제 #30
0
        public static void UpdateBinding(BindingContext newBindingContext, Binding binding)
        {
            BindingManagerBase bindingManagerBase = binding.BindingManagerBase;

            if (bindingManagerBase != null)
            {
                bindingManagerBase.Bindings.Remove(binding);
            }
            if (newBindingContext != null)
            {
                if (binding.BindToObject.BindingManagerBase is PropertyManager)
                {
                    CheckPropertyBindingCycles(newBindingContext, binding);
                }
                BindToObject bindToObject = binding.BindToObject;
                newBindingContext.EnsureListManager(bindToObject.DataSource, bindToObject.BindingMemberInfo.BindingPath).Bindings.Add(binding);
            }
        }
예제 #31
0
파일: Binding.cs 프로젝트: raj581/Marvin
        internal void Check()
        {
            if (control == null || control.BindingContext == null)
            {
                return;
            }

            if (manager == null)
            {
                manager = control.BindingContext [data_source, binding_member_info.BindingPath];

                if (manager.Position > -1 && binding_member_info.BindingField != String.Empty &&
                    TypeDescriptor.GetProperties(manager.Current).Find(binding_member_info.BindingField, true) == null)
                {
                    throw new ArgumentException("Cannot bind to property '" + binding_member_info.BindingField + "' on DataSource.",
                                                "dataMember");
                }

                manager.AddBinding(this);
                manager.PositionChanged += new EventHandler(PositionChangedHandler);

                if (manager is PropertyManager)                   // Match .net, which only watchs simple objects
                {
                    EventDescriptor prop_changed_event = GetPropertyChangedEvent(manager.Current, binding_member_info.BindingField);
                    if (prop_changed_event != null)
                    {
                        prop_changed_event.AddEventHandler(manager.Current, new EventHandler(SourcePropertyChangedHandler));
                    }
                }
            }

            if (manager.Position == -1)
            {
                return;
            }

            if (!checked_isnull)
            {
                is_null_desc   = TypeDescriptor.GetProperties(manager.Current).Find(property_name + "IsNull", false);
                checked_isnull = true;
            }

            PushData();
        }
예제 #32
0
 private void EditTagForm_Load(object sender, System.EventArgs e)
 {
     try
     {
         this.ntb_TagID.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.row.Table, "TagID", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, 0));
         this.tb_TagName.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.row.Table, "TagName", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, ""));
         this.cb_TagType.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.row.Table, "TagType", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, "B"));
         this.tb_Description.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.row.Table, "Description", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, ""));
         this.tb_Note.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.row.Table, "Note", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, ""));
         this.ntb_Code.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.row.Table, "Code", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, 0));
         this.ntb_Max.DataBindings.Add(new System.Windows.Forms.Binding("Value", this.row.Table, "Max", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged, 0));
         System.Windows.Forms.BindingManagerBase bindingManagerBase = this.ntb_TagID.BindingContext[this.row.Table];
         bindingManagerBase.Position = this.rowIndex;
     }
     catch (System.Exception e2)
     {
         Program.showErrorMessage(e2, this);
     }
 }
        internal void Bind(BindingManagerBase parentManager, string dataField) {
            Debug.Assert(parentManager != null, "How could this be a null parentManager.");

            // Unwire previous BindingManagerBase
            UnwireParentManager(this.parentManager);

            this.parentManager = parentManager;
            this.dataField = dataField;
            this.fieldInfo = parentManager.GetItemProperties().Find(dataField, true);
            if (fieldInfo == null || !typeof(IList).IsAssignableFrom(fieldInfo.PropertyType)) {
                throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataField));
            }
            this.finalType = fieldInfo.PropertyType;

            // Wire new BindingManagerBase
            WireParentManager(this.parentManager);

            ParentManager_CurrentItemChanged(parentManager, EventArgs.Empty);
        }
예제 #34
0
		private void EditableBinding_Load(object sender, EventArgs e)
		{
			DataTable dt = Program.StoreDB.GetProducts();

			cboModelName.DataSource = dt;
			cboModelName.DisplayMember = "ModelName";

			Binding costBinding = new Binding("Text", dt, "UnitCost");
			txtUnitCost.DataBindings.Add(costBinding);
			txtModelName.DataBindings.Add("Text", dt, "ModelName");
			txtModelNumber.DataBindings.Add("Text", dt, "ModelNumber");	
			txtDescription.DataBindings.Add("Text", dt, "Description");

			// Keep track of the binding context.
			storeBinding = this.BindingContext[dt];

			dt.ColumnChanged += new DataColumnChangeEventHandler(TableChanged);
			storeBinding.PositionChanged += new EventHandler(Binding_PositionChanged);
		}
예제 #35
0
        public BindingManagerBase this [object dataSource, string dataMember] {
            get {
                if (dataSource == null)
                {
                    throw new ArgumentNullException("dataSource");
                }
                if (dataMember == null)
                {
                    dataMember = String.Empty;
                }

#if NET_2_0
                ICurrencyManagerProvider cm_provider = dataSource as ICurrencyManagerProvider;
                if (cm_provider != null)
                {
                    if (dataMember.Length == 0)
                    {
                        return(cm_provider.CurrencyManager);
                    }

                    return(cm_provider.GetRelatedCurrencyManager(dataMember));
                }
#endif

                HashKey            key = new HashKey(dataSource, dataMember);
                BindingManagerBase res = managers [key] as BindingManagerBase;

                if (res != null)
                {
                    return(res);
                }

                res = CreateBindingManager(dataSource, dataMember);
                if (res == null)
                {
                    return(null);
                }
                managers [key] = res;
                return(res);
            }
        }
예제 #36
0
        internal void Bind(BindingManagerBase parentManager, string dataField)
        {
            Debug.Assert(parentManager != null, "How could this be a null parentManager.");

            // Unwire previous BindingManagerBase
            UnwireParentManager(this.parentManager);

            this.parentManager = parentManager;
            this.dataField     = dataField;
            this.fieldInfo     = parentManager.GetItemProperties().Find(dataField, true);
            if (fieldInfo == null || !typeof(IList).IsAssignableFrom(fieldInfo.PropertyType))
            {
                throw new ArgumentException(string.Format(SR.RelatedListManagerChild, dataField));
            }
            this.finalType = fieldInfo.PropertyType;

            // Wire new BindingManagerBase
            WireParentManager(this.parentManager);

            ParentManager_CurrentItemChanged(parentManager, EventArgs.Empty);
        }
예제 #37
0
 private static void CheckPropertyBindingCycles(BindingContext newBindingContext, Binding propBinding)
 {
     if (((newBindingContext != null) && (propBinding != null)) && newBindingContext.Contains(propBinding.BindableComponent, ""))
     {
         BindingManagerBase base2 = newBindingContext.EnsureListManager(propBinding.BindableComponent, "");
         for (int i = 0; i < base2.Bindings.Count; i++)
         {
             Binding binding = base2.Bindings[i];
             if (binding.DataSource == propBinding.BindableComponent)
             {
                 if (propBinding.BindToObject.BindingMemberInfo.BindingMember.Equals(binding.PropertyName))
                 {
                     throw new ArgumentException(System.Windows.Forms.SR.GetString("DataBindingCycle", new object[] { binding.PropertyName }), "propBinding");
                 }
             }
             else if (propBinding.BindToObject.BindingManagerBase is PropertyManager)
             {
                 CheckPropertyBindingCycles(newBindingContext, binding);
             }
         }
     }
 }
예제 #38
0
        /// <include file='doc\BindingContext.uex' path='docs/doc[@for="BindingContext.UpdateBinding"]/*' />
        /// <devdoc>
        ///     Associates a Binding with a different BindingContext. Intended for use by components that support
        ///     IBindableComponent, to update their Bindings when the value of IBindableComponent.BindingContext
        ///     is changed.
        /// </devdoc>
        public static void UpdateBinding(BindingContext newBindingContext, Binding binding)
        {
            BindingManagerBase oldManager = binding.BindingManagerBase;

            if (oldManager != null)
            {
                oldManager.Bindings.Remove(binding);
            }

            if (newBindingContext != null)
            {
                // we need to first check for cycles before adding this binding to the collection
                // of bindings.
                if (binding.BindToObject.BindingManagerBase is PropertyManager)
                {
                    CheckPropertyBindingCycles(newBindingContext, binding);
                }

                BindToObject       bindTo     = binding.BindToObject;
                BindingManagerBase newManager = newBindingContext.EnsureListManager(bindTo.DataSource, bindTo.BindingMemberInfo.BindingPath);
                newManager.Bindings.Add(binding);
            }
        }
예제 #39
0
        private BindingManagerBase CreateBindingManager(object data_source, string data_member)
        {
            if (data_member == "")
            {
                if (IsListType(data_source.GetType()))
                {
                    return(new CurrencyManager(data_source));
                }
                else
                {
                    return(new PropertyManager(data_source));
                }
            }
            else
            {
                BindingMemberInfo info = new BindingMemberInfo(data_member);

                BindingManagerBase parent_manager = this[data_source, info.BindingPath];

                PropertyDescriptor pd = parent_manager == null ? null : parent_manager.GetItemProperties().Find(info.BindingField, true);

                if (pd == null)
                {
                    throw new ArgumentException(String.Format("Cannot create a child list for field {0}.", info.BindingField));
                }

                if (IsListType(pd.PropertyType))
                {
                    return(new RelatedCurrencyManager(parent_manager, pd));
                }
                else
                {
                    return(new RelatedPropertyManager(parent_manager, info.BindingField));
                }
            }
        }
		// Constructor.
		public RestrictedBindingsCollection(BindingManagerBase mgr)
				{
					this.mgr = mgr;
				}
 private void Set_ErrorManager(object newDataSource, string newDataMember, bool force)
 {
     if (!this.inSetErrorManager)
     {
         this.inSetErrorManager = true;
         try
         {
             bool flag = this.DataSource != newDataSource;
             bool flag2 = this.DataMember != newDataMember;
             if ((flag || flag2) || force)
             {
                 this.dataSource = newDataSource;
                 this.dataMember = newDataMember;
                 if (this.initializing)
                 {
                     this.setErrorManagerOnEndInit = true;
                 }
                 else
                 {
                     this.UnwireEvents(this.errorManager);
                     if (((this.parentControl != null) && (this.dataSource != null)) && (this.parentControl.BindingContext != null))
                     {
                         this.errorManager = this.parentControl.BindingContext[this.dataSource, this.dataMember];
                     }
                     else
                     {
                         this.errorManager = null;
                     }
                     this.WireEvents(this.errorManager);
                     if (this.errorManager != null)
                     {
                         this.UpdateBinding();
                     }
                 }
             }
         }
         finally
         {
             this.inSetErrorManager = false;
         }
     }
 }
예제 #42
0
 // Constructor.
 public RestrictedBindingsCollection(BindingManagerBase mgr)
 {
     this.mgr = mgr;
 }
		protected virtual void AddCore (object dataSource, BindingManagerBase listManager)
		{
			if (dataSource == null)
				throw new ArgumentNullException ("dataSource");
			if (listManager == null)
				throw new ArgumentNullException ("listManager");

			HashKey key = new HashKey (dataSource, String.Empty);
			managers [key] = listManager;
		}
예제 #44
0
        private void UnwireEvents(BindingManagerBase listManager) {
            if (listManager != null) {
                listManager.CurrentChanged -= currentChanged;
                listManager.BindingComplete -= new BindingCompleteEventHandler(this.ErrorManager_BindingComplete);

                CurrencyManager currManager = listManager as CurrencyManager;

                if (currManager != null) {
                    currManager.ItemChanged -= new ItemChangedEventHandler(this.ErrorManager_ItemChanged);
                    currManager.Bindings.CollectionChanged -= new CollectionChangeEventHandler(this.ErrorManager_BindingsChanged);
                }
            }
        }
 static private object GetCurrentOrNull(BindingManagerBase parentManager) {
     bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count);
     return anyCurrent ? parentManager.Current : null;
 }
 internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField) {
     Bind(parentManager, dataField);
 }
예제 #47
0
 internal static void SetBoundItem(BindingManagerBase bmb, object item, string strField, object value)
 {
     PropertyDescriptor descriptor = null;
     if (((item != null) && (strField != null)) && (strField.Length > 0))
     {
         try
         {
             if (bmb != null)
             {
                 descriptor = bmb.GetItemProperties().Find(strField, true);
             }
             else
             {
                 descriptor = TypeDescriptor.GetProperties(item).Find(strField, true);
             }
             if (descriptor != null)
             {
                 descriptor.SetValue(item, ConvertWithNullable(value, descriptor.PropertyType));
             }
         }
         catch (Exception)
         {
             try
             {
                 IConvertible convertible = value as IConvertible;
                 if ((convertible != null) && (descriptor != null))
                 {
                     descriptor.SetValue(item, convertible.ToType(descriptor.PropertyType, CultureInfo.CurrentCulture));
                 }
             }
             catch (Exception)
             {
             }
         }
     }
 }
예제 #48
0
 internal static object GetBoundItem(BindingManagerBase bmb, object item, string strField)
 {
     if (((item != null) && (strField != null)) && (strField.Length > 0))
     {
         try
         {
             PropertyDescriptor descriptor;
             if (bmb != null)
             {
                 descriptor = bmb.GetItemProperties().Find(strField, true);
             }
             else
             {
                 descriptor = TypeDescriptor.GetProperties(item).Find(strField, true);
             }
             if (descriptor != null)
             {
                 item = descriptor.GetValue(item);
             }
         }
         catch (Exception)
         {
         }
     }
     return item;
 }
예제 #49
0
		internal void Check ()
		{
			if (control == null || control.BindingContext == null)
				return;

			if (manager == null) {
				manager = control.BindingContext [data_source, binding_member_info.BindingPath];

				if (manager.Position > -1 && binding_member_info.BindingField != String.Empty &&
					TypeDescriptor.GetProperties (manager.Current).Find (binding_member_info.BindingField, true) == null)
					throw new ArgumentException ("Cannot bind to property '" + binding_member_info.BindingField + "' on DataSource.", 
							"dataMember");

				manager.AddBinding (this);
				manager.PositionChanged += new EventHandler (PositionChangedHandler);

				if (manager is PropertyManager) { // Match .net, which only watchs simple objects
					EventDescriptor prop_changed_event = GetPropertyChangedEvent (manager.Current, binding_member_info.BindingField);
					if (prop_changed_event != null)
						prop_changed_event.AddEventHandler (manager.Current, new EventHandler (SourcePropertyChangedHandler));
				}
			}

			if (manager.Position == -1)
				return;

			if (!checked_isnull) {
				is_null_desc = TypeDescriptor.GetProperties (manager.Current).Find (property_name + "IsNull", false);
				checked_isnull = true;
			}

			PushData ();
		}
 internal ListManagerBindingsCollection(BindingManagerBase bindingManagerBase)
 {
     this.bindingManagerBase = bindingManagerBase;
 }
 /// <include file='doc\ListManagerBindingsCollection.uex' path='docs/doc[@for="ListManagerBindingsCollection.ListManagerBindingsCollection"]/*' />
 /// <devdoc>
 /// ColumnsCollection constructor.  Used only by DataSource.
 /// </devdoc>
 internal ListManagerBindingsCollection(BindingManagerBase bindingManagerBase) : base()
 {
     Debug.Assert(bindingManagerBase != null, "How could a listmanagerbindingscollection not have a bindingManagerBase associated with it!");
     this.bindingManagerBase = bindingManagerBase;
 }
예제 #52
0
 protected override void OnBindingContextChanged(EventArgs e)
 {
     if ((this.BindingContext != null) && (this.DataSource != null))
     {
         this.m_bmb = this.BindingContext[this.DataSource];
         this.m_bmb.CurrentChanged += new EventHandler(this.OnBindingChanged);
     }
     base.OnBindingContextChanged(e);
 }
예제 #53
0
 public Form_Info(SA_DataObject infosource)
     : this()
 {
     this.source = infosource;
       this.Text = this.source.Name;
       this.Icon = Icon.FromHandle((this.source.UIBadge as Bitmap).GetHicon());
       this.pictureBoxUIImage.DataBindings.Add("BackgroundImage", (object) this.source, "UIImage");
       this.pictureBoxUIImage.DataBindings.Add("Image", (object) this.source.Status, "VisualStatusOverlay");
       this.richTextBox1.ReadOnly = true;
       this.richTextBox1.Top = 20;
       this.richTextBox1.DataBindings.Add("Text", (object) this.source.Status, "VerboseStatus");
       if (this.source is Session)
     SA_Reflect.PopulateNonWriteablePanel((object) (this.source as Session).Settings, this.tableLayoutPanelSettings, this.toolTip1, "Indstillinger");
       else
     SA_Reflect.PopulateNonWriteablePanel((object) this.source, this.tableLayoutPanelSettings, this.toolTip1, "Indstillinger");
       SA_Reflect.PopulateNonWriteablePanel((object) this.source, this.tableLayoutPanelStatus, this.toolTip1, "Status");
       if (infosource is SA_BackgroundDataObject)
       {
     (this.source as SA_BackgroundDataObject).UpdateStatus();
     (this.source as SA_BackgroundDataObject).UpdateContent();
     this.tabControl1.TabPages.Remove(this.tabPageLog);
       }
       if (infosource is SA_LoggedDataObject)
       {
     this.dataGridView1.DataSource = (object) (infosource as SA_LoggedDataObject).Log.Entries;
     this.dataGridView1.Columns[0].FillWeight = 15f;
     this.dataGridView1.Columns[1].FillWeight = 15f;
     this.dataGridView1.Columns[2].FillWeight = 70f;
     this.panelUpdateSave.Visible = false;
     this.dataGridViewContent.Dock = DockStyle.Fill;
       }
       if (!(infosource is IContentCarrier))
     this.tabControl1.TabPages.Remove(this.tabPageContent);
       else if (this.source.Content != null)
       {
     this.dataGridViewContent.DataSource = (object) this.source.Content.DefaultView;
     this.bm = this.dataGridViewContent.BindingContext[this.dataGridViewContent.DataSource, this.dataGridViewContent.DataMember];
     this.dataGridViewContent.ContextMenuStrip = new ContextMenuStrip();
     this.dataGridViewContent.MouseUp += new MouseEventHandler(this.dataGridViewContent_MouseUp);
     if (infosource is Session)
     {
       ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem("Vis Detaljer");
       toolStripMenuItem.Click += new EventHandler(this.tm_Click);
       this.dataGridViewContent.ContextMenuStrip.Items.Add((ToolStripItem) toolStripMenuItem);
       this.dataGridViewContent.Columns[0].FillWeight = 15f;
       this.dataGridViewContent.Columns[1].FillWeight = 25f;
       this.dataGridViewContent.Columns[2].FillWeight = 55f;
       this.dataGridViewContent.Columns[3].FillWeight = 5f;
     }
       }
       else
     this.dataGridViewContent.Visible = false;
 }
예제 #54
0
        static private object GetCurrentOrNull(BindingManagerBase parentManager)
        {
            bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count);

            return(anyCurrent ? parentManager.Current : null);
        }
		protected internal void Add (object dataSource, BindingManagerBase listManager)
		{
			AddCore (dataSource, listManager);
			OnCollectionChanged (new CollectionChangeEventArgs (CollectionChangeAction.Add, dataSource));
		}
예제 #56
0
 internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField)
 {
     Bind(parentManager, dataField);
 }
 internal RelatedCurrencyManager(BindingManagerBase parentManager, string dataField) : base(null) {
     Bind(parentManager, dataField);
 }
 internal RelatedCurrencyManager(BindingManagerBase parentManager, string dataField) : base(null)
 {
     Bind(parentManager, dataField);
 }
예제 #59
0
        /// <include file='doc\BindingContext.uex' path='docs/doc[@for="BindingContext.EnsureListManager"]/*' />
        /// <devdoc>
        ///    Create a suitable binding manager for the specified dataSource/dataMember combination.
        ///    - If one has already been created and cached by this BindingContext, return that instead.
        ///    - If the data source is an ICurrencyManagerProvider, just delegate to the data source.
        /// </devdoc>
        internal BindingManagerBase EnsureListManager(object dataSource, string dataMember)
        {
            BindingManagerBase bindingManagerBase = null;

            if (dataMember == null)
            {
                dataMember = "";
            }

            // Check whether data source wants to provide its own binding managers
            // (but fall through to old logic if it fails to provide us with one)
            //
            if (dataSource is ICurrencyManagerProvider)
            {
                bindingManagerBase = (dataSource as ICurrencyManagerProvider).GetRelatedCurrencyManager(dataMember);

                if (bindingManagerBase != null)
                {
                    return(bindingManagerBase);
                }
            }

            // Check for previously created binding manager
            //
            HashKey       key = GetKey(dataSource, dataMember);
            WeakReference wRef;

            wRef = listManagers[key] as WeakReference;
            if (wRef != null)
            {
                bindingManagerBase = (BindingManagerBase)wRef.Target;
            }
            if (bindingManagerBase != null)
            {
                return(bindingManagerBase);
            }

            if (dataMember.Length == 0)
            {
                // No data member specified, so create binding manager directly on the data source
                //
                if (dataSource is IList || dataSource is IListSource)
                {
                    // IListSource so we can bind the dataGrid to a table and a dataSet
                    bindingManagerBase = new CurrencyManager(dataSource);
                }
                else
                {
                    // Otherwise assume simple property binding
                    bindingManagerBase = new PropertyManager(dataSource);
                }
            }
            else
            {
                // Data member specified, so get data source's binding manager, and hook a 'related' binding manager to it
                //
                int    lastDot   = dataMember.LastIndexOf(".");
                string dataPath  = (lastDot == -1) ? "" : dataMember.Substring(0, lastDot);
                string dataField = dataMember.Substring(lastDot + 1);

                BindingManagerBase formerManager = EnsureListManager(dataSource, dataPath);

                PropertyDescriptor prop = formerManager.GetItemProperties().Find(dataField, true);
                if (prop == null)
                {
                    throw new ArgumentException(string.Format(SR.RelatedListManagerChild, dataField));
                }

                if (typeof(IList).IsAssignableFrom(prop.PropertyType))
                {
                    bindingManagerBase = new RelatedCurrencyManager(formerManager, dataField);
                }
                else
                {
                    bindingManagerBase = new RelatedPropertyManager(formerManager, dataField);
                }
            }

            // if wRef == null, then it is the first time we want this bindingManagerBase: so add it
            // if wRef != null, then the bindingManagerBase was GC'ed at some point: keep the old wRef and change its target
            if (wRef == null)
            {
                listManagers.Add(key, new WeakReference(bindingManagerBase, false));
            }
            else
            {
                wRef.Target = bindingManagerBase;
            }

            IntSecurity.UnmanagedCode.Demand();
            ScrubWeakRefs();
            // Return the final binding manager
            return(bindingManagerBase);
        }
예제 #60
0
        private void Set_ErrorManager(object newDataSource, string newDataMember, bool force) {
            if (inSetErrorManager)
                return;
            inSetErrorManager = true;
            try
            {
                bool dataSourceChanged = this.DataSource != newDataSource;
                bool dataMemberChanged = this.DataMember != newDataMember;

                //if nothing changed, then do not do any work
                //
                if (!dataSourceChanged && !dataMemberChanged && !force)
                {
                    return;
                }

                // set the dataSource and the dataMember
                //
                this.dataSource = newDataSource;
                this.dataMember = newDataMember;

                if (initializing) {
                    setErrorManagerOnEndInit = true;
                }
                else {
                    // unwire the errorManager:
                    //
                    UnwireEvents(errorManager);

                    // get the new errorManager
                    //
                    if (parentControl != null && this.dataSource != null && parentControl.BindingContext != null) {
                        errorManager = parentControl.BindingContext[this.dataSource, this.dataMember];
                    }
                    else {
                        errorManager = null;
                    }

                    // wire the events
                    //
                    WireEvents(errorManager);

                    // see if there are errors at the current
                    // item in the list, w/o waiting for the position to change
                    if (errorManager != null)
                        UpdateBinding();
                }
            } finally {
                inSetErrorManager = false;
            }
        }