Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- SerializationObjectManager.cs
- ObjectContextServiceProvider.cs
- Polyline.cs
- CommandEventArgs.cs
- prompt.cs
- ColumnMapTranslator.cs
- PropertiesTab.cs
- DoubleAnimationBase.cs
- DetailsViewPageEventArgs.cs
- XmlElementAttribute.cs
- SrgsGrammar.cs
- AttributeInfo.cs
- SafeThemeHandle.cs
- RegularExpressionValidator.cs
- XmlWriterSettings.cs
- GroupLabel.cs
- ErrorHandler.cs
- _DisconnectOverlappedAsyncResult.cs
- EUCJPEncoding.cs
- XmlQualifiedName.cs
- SaveFileDialog.cs
- CellQuery.cs
- ClientUIRequest.cs
- PreservationFileReader.cs
- VersionedStreamOwner.cs
- ExtendedPropertyDescriptor.cs
- StringArrayEditor.cs
- ToolStripHighContrastRenderer.cs
- HtmlTable.cs
- WebPartVerbCollection.cs
- EventLogReader.cs
- AnalyzedTree.cs
- DriveInfo.cs
- MailMessageEventArgs.cs
- RegisteredArrayDeclaration.cs
- GenericTypeParameterBuilder.cs
- SocketAddress.cs
- SynchronizationContext.cs
- RelationshipEnd.cs
- SystemIdentity.cs
- DataMisalignedException.cs
- CheckBoxAutomationPeer.cs
- Overlapped.cs
- WindowsGraphics.cs
- MediaScriptCommandRoutedEventArgs.cs
- SqlProviderManifest.cs
- ZipArchive.cs
- DrawingContextDrawingContextWalker.cs
- XhtmlBasicCalendarAdapter.cs
- ExpandableObjectConverter.cs
- ExtendedPropertyDescriptor.cs
- XmlRootAttribute.cs
- GC.cs
- ResourceExpression.cs
- HostedNamedPipeTransportManager.cs
- CryptoKeySecurity.cs
- MetadataArtifactLoaderCompositeResource.cs
- XMLSchema.cs
- HtmlFormParameterWriter.cs
- SoapReflectionImporter.cs
- ExternalCalls.cs
- TargetControlTypeAttribute.cs
- SkipQueryOptionExpression.cs
- SoapProtocolImporter.cs
- WebPartHelpVerb.cs
- XamlVector3DCollectionSerializer.cs
- DrawingContextDrawingContextWalker.cs
- EdmScalarPropertyAttribute.cs
- FlowLayout.cs
- ObjectDataSourceFilteringEventArgs.cs
- RegistrationServices.cs
- StringSource.cs
- FloaterBaseParagraph.cs
- FileStream.cs
- DataGridViewCellStyle.cs
- SaveFileDialog.cs
- ModelTreeEnumerator.cs
- FtpCachePolicyElement.cs
- DecoderFallback.cs
- HybridObjectCache.cs
- StateMachine.cs
- CommonProperties.cs
- SqlNamer.cs
- ConfigurationElementProperty.cs
- XmlSerializerAssemblyAttribute.cs
- InputReportEventArgs.cs
- ValidationSummary.cs
- Point3DAnimation.cs
- Package.cs
- LinqToSqlWrapper.cs
- Stacktrace.cs
- ManagementObjectCollection.cs
- CustomErrorsSectionWrapper.cs
- X509ClientCertificateAuthenticationElement.cs
- CollectionViewGroupRoot.cs
- CacheEntry.cs
- ValidationError.cs
- ConfigurationFileMap.cs
- WebPartEditorCancelVerb.cs
- TrackingAnnotationCollection.cs