Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / DataGridDesigner.cs / 1 / DataGridDesigner.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Windows.Forms.Design { using System.Design; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System; using System.Collections; using System.Windows.Forms; using System.Data; using System.ComponentModel.Design; using System.Drawing; using Microsoft.Win32; using System.Windows.Forms.ComponentModel; ////// /// internal class DataGridDesigner : System.Windows.Forms.Design.ControlDesigner { ///Provides a base designer for data grids. ////// /// protected DesignerVerbCollection designerVerbs; private IComponentChangeService changeNotificationService = null; ///Gets the design-time verbs suppoted by the component associated with the /// designer. ////// /// private DataGridDesigner() { designerVerbs = new DesignerVerbCollection(); designerVerbs.Add(new DesignerVerb(SR.GetString(SR.DataGridAutoFormatString), new EventHandler(this.OnAutoFormat))); AutoResizeHandles = true; } public override void Initialize(IComponent component) { base.Initialize(component); IDesignerHost dh = (IDesignerHost) this.GetService(typeof(IDesignerHost)); if (dh != null) { changeNotificationService = (IComponentChangeService) dh.GetService(typeof(IComponentChangeService)); if (changeNotificationService != null) changeNotificationService.ComponentRemoved += new ComponentEventHandler(DataSource_ComponentRemoved); } } private void DataSource_ComponentRemoved(object sender, ComponentEventArgs e) { DataGrid d = (DataGrid) this.Component; if (e.Component == d.DataSource) d.DataSource = null; } protected override void Dispose(bool disposing) { if (disposing) { if (changeNotificationService != null) changeNotificationService.ComponentRemoved -= new ComponentEventHandler(DataSource_ComponentRemoved); } base.Dispose(disposing); } ///Initializes a new instance of the ///class. /// /// public override DesignerVerbCollection Verbs { get { return designerVerbs; } } ///Gets the design-time verbs supported by the component associated with the /// designer. ////// /// [ SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes") // See comment inside the method about ignoring errors. ] private void OnAutoFormat(object sender, EventArgs e) { object o = Component; DataGrid dgrid = o as DataGrid; Debug.Assert(dgrid != null, "DataGrid expected."); DataGridAutoFormatDialog dialog = new DataGridAutoFormatDialog(dgrid); if (dialog.ShowDialog() == DialogResult.OK) { DataRow selectedData = dialog.SelectedData; IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost)); DesignerTransaction trans = host.CreateTransaction(SR.GetString(SR.DataGridAutoFormatUndoTitle, Component.Site.Name)); try { if (selectedData != null) { PropertyDescriptorCollection gridProperties = TypeDescriptor.GetProperties(typeof(DataGrid)); foreach (DataColumn c in selectedData.Table.Columns) { object value = selectedData[c]; PropertyDescriptor prop = gridProperties[c.ColumnName]; if (prop != null) { if (Convert.IsDBNull(value) || value.ToString().Length == 0) { prop.ResetValue(dgrid); } else { try { TypeConverter converter = prop.Converter; object convertedValue = converter.ConvertFromString(value.ToString()); prop.SetValue(dgrid, convertedValue); } catch { // Ignore errors... the only one we really care about is Font names. // The TypeConverter will throw if the font isn't on the user's machine } } } } } } finally { trans.Commit(); } // now invalidate the grid dgrid.Invalidate(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.Raises the AutoFormat event. ///
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- OdbcException.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- ServiceContractViewControl.Designer.cs
- RepeatBehaviorConverter.cs
- InstanceLockLostException.cs
- SqlInfoMessageEvent.cs
- CodeSubDirectoriesCollection.cs
- SignatureHelper.cs
- SecurityState.cs
- CurrencyWrapper.cs
- ThreadStaticAttribute.cs
- WebHttpBinding.cs
- SafeCryptHandles.cs
- DataGridViewAdvancedBorderStyle.cs
- TextParentUndoUnit.cs
- DoubleLinkListEnumerator.cs
- DefaultCommandConverter.cs
- WindowsSecurityTokenAuthenticator.cs
- CalculatedColumn.cs
- DataGridRowClipboardEventArgs.cs
- WebConfigurationHost.cs
- MouseBinding.cs
- MappingMetadataHelper.cs
- GridItemPattern.cs
- DateRangeEvent.cs
- SemanticKeyElement.cs
- LogArchiveSnapshot.cs
- __ComObject.cs
- HttpResponseHeader.cs
- ReaderWriterLock.cs
- SqlCommand.cs
- SubpageParaClient.cs
- HashSetDebugView.cs
- URLMembershipCondition.cs
- Restrictions.cs
- OracleRowUpdatingEventArgs.cs
- ValidationEventArgs.cs
- Panel.cs
- TableStyle.cs
- ChineseLunisolarCalendar.cs
- XamlContextStack.cs
- ProcessManager.cs
- Point4D.cs
- FrameSecurityDescriptor.cs
- CacheModeConverter.cs
- ActivityExecutionFilter.cs
- HttpWriter.cs
- RegexStringValidator.cs
- OperationContext.cs
- SamlAttribute.cs
- WebZone.cs
- XmlAnyAttributeAttribute.cs
- BCLDebug.cs
- WaitHandleCannotBeOpenedException.cs
- XmlBoundElement.cs
- ParagraphVisual.cs
- DependencyObjectCodeDomSerializer.cs
- CustomValidator.cs
- ServiceBuildProvider.cs
- Rect3D.cs
- XslAstAnalyzer.cs
- Delegate.cs
- PreservationFileReader.cs
- BitmapImage.cs
- FloatSumAggregationOperator.cs
- HttpResponse.cs
- DataGridViewRowPrePaintEventArgs.cs
- ObjectIDGenerator.cs
- SynthesizerStateChangedEventArgs.cs
- WriteableBitmap.cs
- securitycriticaldataClass.cs
- CacheChildrenQuery.cs
- GetWinFXPath.cs
- StateMachineSubscription.cs
- TextComposition.cs
- connectionpool.cs
- RoutedEventHandlerInfo.cs
- DataListItemEventArgs.cs
- ReflectionServiceProvider.cs
- MemberDescriptor.cs
- OperatingSystem.cs
- AsmxEndpointPickerExtension.cs
- DefaultHttpHandler.cs
- AuthenticationSection.cs
- ReflectionServiceProvider.cs
- HtmlEncodedRawTextWriter.cs
- StylusPointDescription.cs
- bindurihelper.cs
- ProcessInputEventArgs.cs
- SmtpLoginAuthenticationModule.cs
- FixedPageProcessor.cs
- EmptyQuery.cs
- DetailsViewDeleteEventArgs.cs
- SoapUnknownHeader.cs
- ConfigurationElement.cs
- XmlUtil.cs
- MetadataItem.cs
- EntityCommand.cs
- TemplateComponentConnector.cs
- FileSystemInfo.cs