Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Controls / DataGridClipboardHelper.cs / 1305600 / DataGridClipboardHelper.cs
//---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using System.Windows; namespace System.Windows.Controls { internal static class DataGridClipboardHelper { private const string DATAGRIDVIEW_htmlPrefix = "Version:1.0\r\nStartHTML:00000097\r\nEndHTML:{0}\r\nStartFragment:00000133\r\nEndFragment:{1}\r\n"; private const string DATAGRIDVIEW_htmlStartFragment = "\r\n\r\n"; private const string DATAGRIDVIEW_htmlEndFragment = "\r\n\r\n\r\n"; internal static void FormatCell(object cellValue, bool firstCell, bool lastCell, StringBuilder sb, string format) { bool csv = string.Equals(format, DataFormats.CommaSeparatedValue, StringComparison.OrdinalIgnoreCase); if (csv || string.Equals(format, DataFormats.Text, StringComparison.OrdinalIgnoreCase) || string.Equals(format, DataFormats.UnicodeText, StringComparison.OrdinalIgnoreCase)) { if (cellValue != null) { bool escapeApplied = false; int length = sb.Length; FormatPlainText(cellValue.ToString(), csv, new StringWriter(sb, CultureInfo.CurrentCulture), ref escapeApplied); if (escapeApplied) { sb.Insert(length, '"'); } } if (lastCell) { // Last cell sb.Append('\r'); sb.Append('\n'); } else { sb.Append(csv ? ',' : '\t'); } } else if (string.Equals(format, DataFormats.Html, StringComparison.OrdinalIgnoreCase)) { if (firstCell) { // First cell - append start of row sb.Append(""); } sb.Append(" "); } } } internal static void GetClipboardContentForHtml(StringBuilder content) { content.Insert(0, ""); // Start cell if (cellValue != null) { FormatPlainTextAsHtml(cellValue.ToString(), new StringWriter(sb, CultureInfo.CurrentCulture)); } else { sb.Append(" "); } sb.Append(" "); // End cell if (lastCell) { // Last cell - append end of row sb.Append("
"); break; // default: // The seemingly arbitrary 160 comes from RFC if (ch >= 160 && ch < 256) { output.Write(""); output.Write(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); output.Write(';'); } else { output.Write(ch); } break; } prevCh = ch; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // // Copyright (C) Microsoft Corporation. All rights reserved. // //--------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using System.Windows; namespace System.Windows.Controls { internal static class DataGridClipboardHelper { private const string DATAGRIDVIEW_htmlPrefix = "Version:1.0\r\nStartHTML:00000097\r\nEndHTML:{0}\r\nStartFragment:00000133\r\nEndFragment:{1}\r\n"; private const string DATAGRIDVIEW_htmlStartFragment = "\r\n\r\n"; private const string DATAGRIDVIEW_htmlEndFragment = "\r\n\r\n\r\n"; internal static void FormatCell(object cellValue, bool firstCell, bool lastCell, StringBuilder sb, string format) { bool csv = string.Equals(format, DataFormats.CommaSeparatedValue, StringComparison.OrdinalIgnoreCase); if (csv || string.Equals(format, DataFormats.Text, StringComparison.OrdinalIgnoreCase) || string.Equals(format, DataFormats.UnicodeText, StringComparison.OrdinalIgnoreCase)) { if (cellValue != null) { bool escapeApplied = false; int length = sb.Length; FormatPlainText(cellValue.ToString(), csv, new StringWriter(sb, CultureInfo.CurrentCulture), ref escapeApplied); if (escapeApplied) { sb.Insert(length, '"'); } } if (lastCell) { // Last cell sb.Append('\r'); sb.Append('\n'); } else { sb.Append(csv ? ',' : '\t'); } } else if (string.Equals(format, DataFormats.Html, StringComparison.OrdinalIgnoreCase)) { if (firstCell) { // First cell - append start of row sb.Append("
"); break; // default: // The seemingly arbitrary 160 comes from RFC if (ch >= 160 && ch < 256) { output.Write(""); output.Write(((int)ch).ToString(NumberFormatInfo.InvariantInfo)); output.Write(';'); } else { output.Write(ch); } break; } prevCh = ch; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Converter.cs
- DynamicControl.cs
- CodeCommentStatementCollection.cs
- CopyNodeSetAction.cs
- XmlSchemaGroupRef.cs
- ScriptRef.cs
- CacheRequest.cs
- Stackframe.cs
- DbConnectionPoolCounters.cs
- Size.cs
- XPathBuilder.cs
- CollectionViewGroupRoot.cs
- XmlStreamStore.cs
- DesignBindingPicker.cs
- TransactionChannelListener.cs
- UrlPath.cs
- SqlBulkCopyColumnMappingCollection.cs
- AttachedPropertyBrowsableAttribute.cs
- AnnotationObservableCollection.cs
- ActivityPropertyReference.cs
- TransactionInformation.cs
- indexingfiltermarshaler.cs
- FixUpCollection.cs
- GridSplitterAutomationPeer.cs
- EventSetterHandlerConverter.cs
- ListContractAdapter.cs
- PropertyMapper.cs
- parserscommon.cs
- ActivationArguments.cs
- DummyDataSource.cs
- UrlPath.cs
- DebugController.cs
- ComponentCodeDomSerializer.cs
- RichTextBoxConstants.cs
- ObjectStateFormatter.cs
- TreeWalker.cs
- Activity.cs
- XhtmlBasicPageAdapter.cs
- Identifier.cs
- ExtendedProperty.cs
- AttributeCollection.cs
- VarInfo.cs
- _CookieModule.cs
- GPPOINTF.cs
- SHA384Managed.cs
- EventLogHandle.cs
- UserNamePasswordClientCredential.cs
- ToolboxComponentsCreatedEventArgs.cs
- InputDevice.cs
- SingleObjectCollection.cs
- InternalMappingException.cs
- ReservationNotFoundException.cs
- ProcessHostServerConfig.cs
- RelationshipEntry.cs
- DomNameTable.cs
- GlobalEventManager.cs
- graph.cs
- DataColumnSelectionConverter.cs
- EnumValAlphaComparer.cs
- ManualResetEvent.cs
- BitmapEffectGeneralTransform.cs
- EntryIndex.cs
- WebPartRestoreVerb.cs
- ProcessModelInfo.cs
- ZoneMembershipCondition.cs
- CatalogZoneBase.cs
- ConnectionStringSettingsCollection.cs
- FormatConvertedBitmap.cs
- SqlInfoMessageEvent.cs
- Schema.cs
- HotSpotCollection.cs
- UxThemeWrapper.cs
- SQlBooleanStorage.cs
- SymmetricSecurityBindingElement.cs
- TaiwanLunisolarCalendar.cs
- XsltCompileContext.cs
- GridViewCommandEventArgs.cs
- InvalidCastException.cs
- AddInAdapter.cs
- ErrorEventArgs.cs
- TimeSpanOrInfiniteValidator.cs
- SectionInput.cs
- FileLogRecordHeader.cs
- ListBoxAutomationPeer.cs
- CodeAttachEventStatement.cs
- XmlReaderSettings.cs
- StickyNote.cs
- XmlSchemaSimpleContent.cs
- HttpException.cs
- fixedPageContentExtractor.cs
- SqlDependencyUtils.cs
- WizardStepBase.cs
- DependencySource.cs
- NeutralResourcesLanguageAttribute.cs
- LinkedResourceCollection.cs
- InputBinding.cs
- Hashtable.cs
- Matrix3DConverter.cs
- MouseEvent.cs
- DataServiceResponse.cs