Xceed.Silverlight.DataGrid.v2.0 Assembly > Xceed.Silverlight.DataGrid.Export Namespace > ExporterBase Class : Export Method |
'Declaration Public Sub Export( _ ByVal stream As Stream, _ ByVal selectionRanges As IList(Of SelectionRange) _ )
'Usage Dim instance As ExporterBase Dim stream As Stream Dim selectionRanges As IList(Of SelectionRange) instance.Export(stream, selectionRanges)
public void Export( Stream stream, IList<SelectionRange> selectionRanges )
For asynchronous export operations, the BeginExport method can be used.
<sldg:DataGridControl x:Name="sldgDataGridControl" ItemsSource="{Binding Path=People}"> <sldg:DataGridControl.FixedFooters> <Button Content="Copy To Clipboard" Click="CsvExport_Click"/> </sldg:DataGridControl.FixedFooters> </sldg:DataGridControl>
Private Sub CsvExport_Click( ByVal sender As Object, ByVal e As RoutedEventArgs ) If Me.sldgDataGridControl.SelectedRanges.Count > 0 Then Me.ExportToCsv( Me.sldgDataGridControl.SelectedRanges ) End If End Sub Private Sub ExportToCsv( ByVal selectionRanges As IList( Of SelectionRange ) ) Dim csvExporter As New CsvExporter( Me.sldgDataGridControl ) csvExporter.IncludeColumnHeaders = False 'Set properties that are null by default. csvExporter.FormatSettings.Culture = CultureInfo.CurrentCulture csvExporter.FormatSettings.Separator = ';' Dim stream AS new MemoryStream() ' Call the synchronous method, so the items can be pasted to the clipboard within a user-initiated event. csvExporter.Export( stream, selectionRanges ) Me.CopyItemsToClipboard( stream ) stream.Close() stream.Dispose() End Sub Private Sub CopyItemsToClipboard( ByVal stream As Stream ) Dim copyboardText As String = String.Empty Dim encoding As Encoding = Encoding.Unicode Dim buffer As New Byte( 32768 ) Dim bytesRead As Integer = 0 stream.Position = 0 ' Get the content of the exported stream as a string. While( ( bytesRead = stream.Read( buffer, 0, buffer.Length ) ) > 0 ) copyboardText += encoding.GetString( buffer, 0, bytesRead ) End While ' Copy it to the clipboard. Clipboard.SetText( copyboardText ) End Sub
private void CsvExport_Click( object sender, RoutedEventArgs e ) { if( this.sldgDataGridControl.SelectedRanges.Count > 0 ) this.ExportToCsv( this.sldgDataGridControl.SelectedRanges ); } private void ExportToCsv( IList<SelectionRange> selectionRanges ) { CsvExporter csvExporter = new CsvExporter( this.sldgDataGridControl ); csvExporter.IncludeColumnHeaders = false; //Set properties that are null by default. csvExporter.FormatSettings.Culture = CultureInfo.CurrentCulture; csvExporter.FormatSettings.Separator = ';'; using( Stream stream = new MemoryStream() ) { // Call the synchronous method, so the items can be pasted to the clipboard within a user-initiated event. csvExporter.Export( stream, selectionRanges ); this.CopyItemsToClipboard( stream ); stream.Close(); } } private void CopyItemsToClipboard( Stream stream ) { string copyboardText = string.Empty; Encoding encoding = Encoding.Unicode; byte[] buffer = new byte[ 32768 ]; int bytesRead = 0; stream.Position = 0; // Get the content of the exported stream as a string. while( ( bytesRead = stream.Read( buffer, 0, buffer.Length ) ) > 0 ) { copyboardText += encoding.GetString( buffer, 0, bytesRead ); } // Copy it to the clipboard. Clipboard.SetText( copyboardText ); }
Target Platforms: Windows 7, Windows Vista, Windows XP SP3, Windows Server 2008 family