/// <summary> /// Publish Dependant Component Changes /// </summary> /// <typeparam name="T">Type of property</typeparam> /// <param name="propertyName">Property Name that has changed</param> /// <param name="value">new value for Property</param> private void PublishDependentComponentChanges <T>(string propertyName, T value) { System.ComponentModel.Design.IComponentChangeService changeService = null; System.ComponentModel.PropertyDescriptor property = null; T currentValue = default(T); if (DesignMode && this.Site != null) { property = System.ComponentModel.TypeDescriptor.GetProperties(this)[propertyName]; changeService = (System.ComponentModel.Design.IComponentChangeService) this.Site.GetService(typeof(System.ComponentModel.Design.IComponentChangeService)); if (changeService != null) { currentValue = (T)property.GetValue(this); if (currentValue == null) { currentValue = default(T); } // Trap any error and ignore it changeService.OnComponentChanging(this, property); // try to set new value property.SetValue(this, value); changeService.OnComponentChanged(this, property, currentValue, value); } } }
/// <summary> /// Call the dialog to edit the TableMappings /// </summary> /// <param name="context"></param> /// <param name="provider">Service provider.</param> /// <param name="value">DataTableMappingCollection object.</param> /// <returns></returns> public override object EditValue( ITypeDescriptorContext context, IServiceProvider provider, object value) // DataTableMappingCollection object { if (context != null && context.Instance != null && provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService( typeof(IWindowsFormsEditorService)); if (edSvc != null) { System.ComponentModel.Design.IDesignerHost host = provider.GetService( typeof(System.ComponentModel.Design.IDesignerHost)) as System.ComponentModel.Design.IDesignerHost; if (host == null) { System.Windows.Forms.MessageBox.Show( "The IDesignerHost service interface " + "could not be obtained to process the request.", "Table Mappings"); return(value); } System.ComponentModel.Design.IComponentChangeService chgSvc = provider.GetService( typeof(System.ComponentModel.Design.IComponentChangeService)) as System.ComponentModel.Design.IComponentChangeService; if (chgSvc == null) { System.Windows.Forms.MessageBox.Show( "The IComponentChangeService service interface " + "could not be obtained to process the request.", "Table Mappings"); return(value); } if (!context.OnComponentChanging()) { System.Windows.Forms.MessageBox.Show( "The component is not permitted to be changed.", "Table Mappings"); return(value); } System.ComponentModel.Design.DesignerTransaction designerTxn = host.CreateTransaction("TableMapping"); DbDataAdapter adapter = (DbDataAdapter)context.Instance; Form form = new TableMapForm(adapter); chgSvc.OnComponentChanging(adapter, null); using (form) { using (designerTxn) { try { DialogResult result = edSvc.ShowDialog(form); if (result == DialogResult.OK) { designerTxn.Commit(); } else { designerTxn.Cancel(); } } finally { chgSvc.OnComponentChanged(adapter, null, null, null); // context.OnComponentChanged(); } } } } // end if (edSvc != null) } // end if context is OK return(value); }