Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- webeventbuffer.cs
- LayoutExceptionEventArgs.cs
- XsltFunctions.cs
- CfgSemanticTag.cs
- PreservationFileWriter.cs
- ListViewGroupItemCollection.cs
- FreezableOperations.cs
- FontStyle.cs
- SecurityTokenTypes.cs
- Triangle.cs
- RegisteredHiddenField.cs
- ContextMenu.cs
- Permission.cs
- Floater.cs
- InternalPermissions.cs
- TraceContext.cs
- X509SubjectKeyIdentifierClause.cs
- BufferedGraphicsManager.cs
- BitmapInitialize.cs
- ValidatorUtils.cs
- PropertyTabAttribute.cs
- Label.cs
- AssertSection.cs
- LogLogRecordEnumerator.cs
- HttpListenerException.cs
- XdrBuilder.cs
- ToolStripGripRenderEventArgs.cs
- MouseActionConverter.cs
- RedirectionProxy.cs
- DesignerAttribute.cs
- Utility.cs
- diagnosticsswitches.cs
- DocumentOrderComparer.cs
- ValidationEventArgs.cs
- BufferModeSettings.cs
- SettingsPropertyValue.cs
- SqlTriggerAttribute.cs
- ClassImporter.cs
- TextShapeableCharacters.cs
- HttpRuntime.cs
- OdbcDataAdapter.cs
- PrinterResolution.cs
- DataGridViewSortCompareEventArgs.cs
- ObjectConverter.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- ActivityDefaults.cs
- ItemsPanelTemplate.cs
- StorageMappingFragment.cs
- WMIInterop.cs
- MetadataHelper.cs
- BookmarkUndoUnit.cs
- HighContrastHelper.cs
- TokenizerHelper.cs
- Selection.cs
- ReaderWriterLockWrapper.cs
- RichTextBox.cs
- COM2EnumConverter.cs
- ToolStripRenderer.cs
- filewebresponse.cs
- HtmlInputPassword.cs
- BasePattern.cs
- SynchronizedKeyedCollection.cs
- OdbcCommand.cs
- SemaphoreSecurity.cs
- DataRelationCollection.cs
- SQLRoleProvider.cs
- invalidudtexception.cs
- RotateTransform3D.cs
- TextModifierScope.cs
- FtpWebResponse.cs
- BamlCollectionHolder.cs
- SqlDataSourceConfigureSortForm.cs
- DataMember.cs
- ComNativeDescriptor.cs
- TreeBuilderXamlTranslator.cs
- FunctionImportMapping.cs
- DriveNotFoundException.cs
- XmlDeclaration.cs
- Animatable.cs
- ExecutionEngineException.cs
- ShortcutKeysEditor.cs
- ShaperBuffers.cs
- UnsafeNativeMethods.cs
- Translator.cs
- InstanceNormalEvent.cs
- FilePresentation.cs
- ClientData.cs
- _UncName.cs
- xmlsaver.cs
- CodeExpressionStatement.cs
- VisualProxy.cs
- Emitter.cs
- ConfigXmlWhitespace.cs
- DataShape.cs
- SmiContext.cs
- XmlnsCache.cs
- _OverlappedAsyncResult.cs
- SessionIDManager.cs
- CommandValueSerializer.cs
- DbProviderFactories.cs