Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / WinForms / Managed / System / WinForms / RelatedPropertyManager.cs / 1 / RelatedPropertyManager.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using Microsoft.Win32; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.ComponentModel; using System.Collections; internal class RelatedPropertyManager : PropertyManager { BindingManagerBase parentManager; string dataField; PropertyDescriptor fieldInfo; [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // If the constructor does not set the dataSource // it would be a breaking change. ] internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField) { Bind(parentManager, dataField); } 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(); } internal override string GetListName() { string name = GetListName(new ArrayList()); if (name.Length > 0) { return name; } return base.GetListName(); } protected internal override string GetListName(ArrayList listAccessors) { listAccessors.Insert(0, fieldInfo); return parentManager.GetListName(listAccessors); } 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); } private void ParentManager_CurrentItemChanged(object sender, EventArgs e) { Refresh(); } private void Refresh() { EndCurrentEdit(); SetDataSource(GetCurrentOrNull(parentManager)); OnCurrentChanged(EventArgs.Empty); } internal override Type BindType { get { return fieldInfo.PropertyType; } } public override object Current { get { return (this.DataSource != null) ? fieldInfo.GetValue(this.DataSource) : null; } } static private object GetCurrentOrNull(BindingManagerBase parentManager) { bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count); return anyCurrent ? parentManager.Current : null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms { using System; using Microsoft.Win32; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.ComponentModel; using System.Collections; internal class RelatedPropertyManager : PropertyManager { BindingManagerBase parentManager; string dataField; PropertyDescriptor fieldInfo; [ SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors") // If the constructor does not set the dataSource // it would be a breaking change. ] internal RelatedPropertyManager(BindingManagerBase parentManager, string dataField) : base(GetCurrentOrNull(parentManager), dataField) { Bind(parentManager, dataField); } 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(); } internal override string GetListName() { string name = GetListName(new ArrayList()); if (name.Length > 0) { return name; } return base.GetListName(); } protected internal override string GetListName(ArrayList listAccessors) { listAccessors.Insert(0, fieldInfo); return parentManager.GetListName(listAccessors); } 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); } private void ParentManager_CurrentItemChanged(object sender, EventArgs e) { Refresh(); } private void Refresh() { EndCurrentEdit(); SetDataSource(GetCurrentOrNull(parentManager)); OnCurrentChanged(EventArgs.Empty); } internal override Type BindType { get { return fieldInfo.PropertyType; } } public override object Current { get { return (this.DataSource != null) ? fieldInfo.GetValue(this.DataSource) : null; } } static private object GetCurrentOrNull(BindingManagerBase parentManager) { bool anyCurrent = (parentManager.Position >= 0 && parentManager.Position < parentManager.Count); return anyCurrent ? parentManager.Current : null; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CngUIPolicy.cs
- ContentPosition.cs
- DescendentsWalkerBase.cs
- CompModSwitches.cs
- DiscoveryClientProtocol.cs
- DataServiceRequestException.cs
- ReachPageContentSerializerAsync.cs
- DataServiceException.cs
- CompilationUtil.cs
- PolyBezierSegment.cs
- VBIdentifierTrimConverter.cs
- SymbolType.cs
- DrawListViewColumnHeaderEventArgs.cs
- WebPartManager.cs
- LayoutSettings.cs
- FileLoadException.cs
- DiscoveryClientRequestChannel.cs
- UpdatePanel.cs
- unitconverter.cs
- CallSite.cs
- SafeLibraryHandle.cs
- EntityDataSourceEntityTypeFilterItem.cs
- RadioButtonAutomationPeer.cs
- SystemParameters.cs
- ForeignKeyConstraint.cs
- LightweightCodeGenerator.cs
- ComponentDispatcher.cs
- TreeViewItem.cs
- BufferedGraphicsContext.cs
- ClonableStack.cs
- TypeListConverter.cs
- BufferedGraphics.cs
- FormatterServices.cs
- Validator.cs
- SafeNativeMethods.cs
- EventSinkHelperWriter.cs
- CounterCreationData.cs
- StringKeyFrameCollection.cs
- ToolStripRenderer.cs
- TriState.cs
- Help.cs
- CheckBox.cs
- CssTextWriter.cs
- PerformanceCountersElement.cs
- CommonEndpointBehaviorElement.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- CLRBindingWorker.cs
- WorkflowElementDialog.cs
- Pkcs9Attribute.cs
- SpellCheck.cs
- LineBreakRecord.cs
- _SingleItemRequestCache.cs
- WindowsIdentity.cs
- RangeContentEnumerator.cs
- ManagedIStream.cs
- ComboBox.cs
- Inline.cs
- AnnotationAuthorChangedEventArgs.cs
- ContentTextAutomationPeer.cs
- BinaryWriter.cs
- TopClause.cs
- InstallerTypeAttribute.cs
- SafeTokenHandle.cs
- SafeCryptoHandles.cs
- CustomPopupPlacement.cs
- Predicate.cs
- typedescriptorpermission.cs
- MetafileHeaderWmf.cs
- RichTextBox.cs
- MapPathBasedVirtualPathProvider.cs
- DocumentViewerBaseAutomationPeer.cs
- AppDomainProtocolHandler.cs
- ListViewCommandEventArgs.cs
- TextEditorTyping.cs
- GlyphRun.cs
- AstTree.cs
- ValueTable.cs
- RequestResizeEvent.cs
- SkewTransform.cs
- SlotInfo.cs
- XmlDataSource.cs
- StringExpressionSet.cs
- XmlChildEnumerator.cs
- SoapMessage.cs
- Int32Converter.cs
- EventMappingSettings.cs
- UserMapPath.cs
- WorkflowServiceInstance.cs
- SessionStateItemCollection.cs
- MappingModelBuildProvider.cs
- Exception.cs
- TextServicesManager.cs
- Padding.cs
- ACE.cs
- TabPage.cs
- ProfileGroupSettings.cs
- OciLobLocator.cs
- ZipIOLocalFileBlock.cs
- SqlDataSourceFilteringEventArgs.cs
- AutomationPropertyInfo.cs