public override PropertyDescriptorCollection GetItemProperties() { PropertyDescriptor property = parent.GetItemProperties().Find(property_name, true); // We can't just pass property.PropertyType, since the actual object could implement // more elements and not only those described in the property type return(TypeDescriptor.GetProperties(property.GetValue(parent.Current))); }
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(); }
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); }
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 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); }
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); }
internal override PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { PropertyDescriptor[] accessors; if (listAccessors != null && listAccessors.Length > 0) { accessors = new PropertyDescriptor[listAccessors.Length + 1]; listAccessors.CopyTo(accessors, 1); } else { accessors = new PropertyDescriptor[1]; } // Set this accessor (add to the beginning) accessors[0] = this.fieldInfo; // Get props return(parentManager.GetItemProperties(accessors)); }
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); }
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)); } } }
internal BindingManagerBase EnsureListManager(object dataSource, string dataMember) { if (dataMember == null) { dataMember = ""; } HashKey key = GetKey(dataSource, dataMember); WeakReference wRef; BindingManagerBase bindingManagerBase = null; wRef = listManagers[key] as WeakReference; if (wRef != null) { bindingManagerBase = (BindingManagerBase)wRef.Target; } if (bindingManagerBase != null) { return(bindingManagerBase); } // create base listManager. if (dataMember.Length == 0) { //IListSource so we can bind the dataGrid to a table and a dataSet if (dataSource is IList || dataSource is IListSource) { bindingManagerBase = new CurrencyManager(dataSource); } else { bindingManagerBase = new PropertyManager(dataSource); } // 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; } return(bindingManagerBase); } // handle relation. int lastDot = dataMember.LastIndexOf("."); BindingManagerBase formerManager = EnsureListManager(dataSource, lastDot == -1 ? "" : dataMember.Substring(0, lastDot)); PropertyDescriptor prop = formerManager.GetItemProperties().Find(dataMember.Substring(lastDot + 1), true); if (prop == null) { throw new ArgumentException(SR.GetString(SR.RelatedListManagerChild, dataMember.Substring(lastDot + 1))); } if (typeof(IList).IsAssignableFrom(prop.PropertyType)) { bindingManagerBase = new RelatedCurrencyManager(formerManager, dataMember.Substring(lastDot + 1)); } else { bindingManagerBase = new RelatedPropertyManager(formerManager, dataMember.Substring(lastDot + 1)); } // 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(GetKey(dataSource, dataMember), new WeakReference(bindingManagerBase, false)); } else { wRef.Target = bindingManagerBase; } return(bindingManagerBase); }
/// <include file='doc\RelatedListManager.uex' path='docs/doc[@for="RelatedCurrencyManager.GetItemProperties1"]/*' /> /// <devdoc> /// <para>Gets the properties of the item using the specified list.</para> /// </devdoc> protected internal override PropertyDescriptorCollection GetItemProperties(ArrayList dataSources, ArrayList listAccessors) { listAccessors.Insert(0, fieldInfo); dataSources.Insert(0, this.DataSource); return(parentManager.GetItemProperties(dataSources, listAccessors)); }
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) { } } } }
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; }
internal BindingManagerBase EnsureListManager(object dataSource, string dataMember) { BindingManagerBase target = null; if (dataMember == null) { dataMember = ""; } if (dataSource is ICurrencyManagerProvider) { target = (dataSource as ICurrencyManagerProvider).GetRelatedCurrencyManager(dataMember); if (target != null) { return(target); } } HashKey key = this.GetKey(dataSource, dataMember); WeakReference reference = this.listManagers[key] as WeakReference; if (reference != null) { target = (BindingManagerBase)reference.Target; } if (target == null) { if (dataMember.Length == 0) { if ((dataSource is IList) || (dataSource is IListSource)) { target = new CurrencyManager(dataSource); } else { target = new PropertyManager(dataSource); } } else { int length = dataMember.LastIndexOf("."); string str = (length == -1) ? "" : dataMember.Substring(0, length); string name = dataMember.Substring(length + 1); BindingManagerBase parentManager = this.EnsureListManager(dataSource, str); PropertyDescriptor descriptor = parentManager.GetItemProperties().Find(name, true); if (descriptor == null) { throw new ArgumentException(System.Windows.Forms.SR.GetString("RelatedListManagerChild", new object[] { name })); } if (typeof(IList).IsAssignableFrom(descriptor.PropertyType)) { target = new RelatedCurrencyManager(parentManager, name); } else { target = new RelatedPropertyManager(parentManager, name); } } if (reference == null) { this.listManagers.Add(key, new WeakReference(target, false)); return(target); } reference.Target = target; } return(target); }
/// <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); }