Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StackOverflowException.cs
- OverflowException.cs
- MSAAEventDispatcher.cs
- ButtonChrome.cs
- AspCompat.cs
- MenuItemAutomationPeer.cs
- RootBuilder.cs
- BufferedStream.cs
- DotExpr.cs
- XmlCollation.cs
- ZipIOCentralDirectoryBlock.cs
- XmlDocumentType.cs
- Rect3DConverter.cs
- DropShadowBitmapEffect.cs
- HtmlTableRow.cs
- ContactManager.cs
- SqlTrackingQuery.cs
- SendMailErrorEventArgs.cs
- ObjectQueryState.cs
- VirtualizedItemProviderWrapper.cs
- OverlappedAsyncResult.cs
- VBIdentifierDesigner.xaml.cs
- IChannel.cs
- EntityDataSourceDataSelectionPanel.cs
- RegistryExceptionHelper.cs
- XPathBinder.cs
- SymbolType.cs
- HttpRuntimeSection.cs
- SafeThreadHandle.cs
- cache.cs
- AmbientValueAttribute.cs
- VectorCollectionConverter.cs
- AsyncResult.cs
- AssociationSetEnd.cs
- ExpressionServices.cs
- GPStream.cs
- DecoderExceptionFallback.cs
- EntityModelBuildProvider.cs
- Binding.cs
- CodeVariableDeclarationStatement.cs
- ControlType.cs
- NameValuePermission.cs
- FacetChecker.cs
- Binding.cs
- FileSystemInfo.cs
- LifetimeManager.cs
- RelationshipWrapper.cs
- GorillaCodec.cs
- TabControlDesigner.cs
- ReservationCollection.cs
- BypassElementCollection.cs
- Ref.cs
- InternalBufferOverflowException.cs
- MarkupCompilePass2.cs
- DbConnectionPoolIdentity.cs
- ReceiveSecurityHeader.cs
- TdsValueSetter.cs
- GeneralTransformGroup.cs
- DataGrid.cs
- ToolStripDesignerAvailabilityAttribute.cs
- CacheSection.cs
- HitTestParameters3D.cs
- ControlBuilder.cs
- IItemProperties.cs
- MemoryRecordBuffer.cs
- BrowserTree.cs
- DataGridItemCollection.cs
- HandlerFactoryWrapper.cs
- BindingNavigator.cs
- BasePropertyDescriptor.cs
- WebDescriptionAttribute.cs
- KeyEventArgs.cs
- smtpconnection.cs
- InvokeMethod.cs
- TextEffect.cs
- TemplatePropertyEntry.cs
- ListViewItemMouseHoverEvent.cs
- Soap12ServerProtocol.cs
- StickyNoteHelper.cs
- OSEnvironmentHelper.cs
- ThreadAbortException.cs
- RegexCaptureCollection.cs
- Rotation3D.cs
- DES.cs
- FixedPageProcessor.cs
- ControlBindingsCollection.cs
- SerializationInfoEnumerator.cs
- RectConverter.cs
- QilExpression.cs
- MatrixCamera.cs
- ToolStripPanelRenderEventArgs.cs
- SQLSingleStorage.cs
- XmlTextWriter.cs
- PersistenceException.cs
- PersistenceContextEnlistment.cs
- OneWayElement.cs
- Comparer.cs
- filewebresponse.cs
- BindingCompleteEventArgs.cs
- EditorBrowsableAttribute.cs