Xceed DataGrid for Silverlight Documentation
Export Method
Example 


The Stream to which the data items will be exported.
An IList of the SelectionRange objects representing the data items to be exported. If a null reference (Nothing in Visual Basic), all items will be exported.
Synchronously exports the specified data items to the provided stream.
Syntax
'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
)

Parameters

stream
The Stream to which the data items will be exported.
selectionRanges
An IList of the SelectionRange objects representing the data items to be exported. If a null reference (Nothing in Visual Basic), all items will be exported.
Remarks

For asynchronous export operations, the BeginExport method can be used.

Example
This example demonstrates how to synchronously export to the clipboard using CSV format.
<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 );
}
Requirements

Target Platforms: Windows 7, Windows Vista, Windows XP SP3, Windows Server 2008 family

See Also

Reference

ExporterBase Class
ExporterBase Members
BeginExport Method

Manipulating Data

Exporting Data

Send Feedback