Version

ClipboardCopying Event

Occurs when the DataPresenterCommands.Copy or DataPresenterCommands.Cut command is executed and the cell values will be placed on the clipboard.
Syntax
'Declaration
 
Public Event ClipboardCopying As EventHandler(Of ClipboardCopyingEventArgs)
public event EventHandler<ClipboardCopyingEventArgs> ClipboardCopying
Event Data

The event handler receives an argument of type ClipboardCopyingEventArgs containing data related to this event. The following ClipboardCopyingEventArgs properties provide information specific to this event.

PropertyDescription
Cancel (Inherited from Infragistics.Windows.Controls.Events.CancelableRoutedEventArgs) 
FieldCount (Inherited from Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgs)Returns the number of fields represented in the collection.
Handled (Inherited from System.Windows.RoutedEventArgs)Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route.
OriginalSource (Inherited from System.Windows.RoutedEventArgs)Gets the original reporting source as determined by pure hit testing, before any possible System.Windows.RoutedEventArgs.Source adjustment by a parent class.
RecordCount (Inherited from Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgs)Returns the number of records represented in the collection.
RoutedEvent (Inherited from System.Windows.RoutedEventArgs)Gets or sets the System.Windows.RoutedEventArgs.RoutedEvent associated with this System.Windows.RoutedEventArgs instance.
Source (Inherited from System.Windows.RoutedEventArgs)Gets or sets a reference to the object that raised the event.
Values (Inherited from Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgs)Returns a collection of the unconverted values to be used as the source for the clipboard operation.
Remarks

This event can be used to provide the formatted values that will be placed on the clipboard.

Example
The following sample demonstrates how to use the ClipboardCopying event to provide a custom formatted version of the value that should be used in the output put into the clipboard.

For an overview of how to handle events in Visual Basic or Visual C#, see Event Handlers in Visual Basic and Visual C#. For specific information and code examples illustrating how to consume events in your application, see Consuming Events in the .NET Framework Developer's Guide.

Imports Infragistics.Windows.DataPresenter
Imports System.Globalization

    Private Sub grid_ClipboardCopying(ByVal sender As System.Object, ByVal e As Infragistics.Windows.DataPresenter.Events.ClipboardCopyingEventArgs)
        Dim dp As DataPresenterBase = DirectCast(sender, DataPresenterBase)
        Dim notPercentField As Field = dp.DefaultFieldLayout.Fields("NotPercent")
        Dim fldIndex As Integer = e.GetSourceFieldIndex(notPercentField)

        ' the not percent field displays in exponential but to output the 
        ' value in another format, we can change the value of the associated 
        ' cell value holders
        If fldIndex >= 0 Then
            For i As Integer = 0 To e.RecordCount - 1
                Dim cvh As CellValueHolder = e.Values(i, fldIndex)

                If Not cvh Is Nothing AndAlso Not cvh.IsDisplayText AndAlso TypeOf cvh.Value Is Double Then
                    Dim dblValue As Double = CType(cvh.Value, Double)
                    cvh.Value = dblValue.ToString("R")
                    cvh.IsDisplayText = True
                End If
            Next
        End If
    End Sub

    Private Sub grid_InitializeRecord(ByVal sender As System.Object, ByVal e As Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs)
        If Not e.ReInitialize Then
            Dim dr As DataRecord = TryCast(e.Record, DataRecord)

            If Not dr Is Nothing Then
                dr.Cells("NotPercent").Value = 0.25
            End If
        End If
    End Sub
using Infragistics.Windows.DataPresenter;
using System.Globalization;

	private void grid_ClipboardCopying(object sender, Infragistics.Windows.DataPresenter.Events.ClipboardCopyingEventArgs e)
	{
		DataPresenterBase dp = sender as DataPresenterBase;
		Field notPercentField = dp.DefaultFieldLayout.Fields["NotPercent"];
		int fldIndex = e.GetSourceFieldIndex(notPercentField);

		// the not percent field displays in exponential but to output the 
		// value in another format, we can change the value of the associated 
		// cell value holders
		if (fldIndex >= 0)
		{
			for (int i = 0, count = e.RecordCount; i < count; i++)
			{
				CellValueHolder cvh = e.Values[i, fldIndex];

				if (null != cvh && !cvh.IsDisplayText && cvh.Value is double)
				{
					double dblValue = (double)cvh.Value;
					cvh.Value = dblValue.ToString("R");
					cvh.IsDisplayText = true;
				}
			}
		}
	}

	private void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
	{
		if (!e.ReInitialize)
		{
			DataRecord dr = e.Record as DataRecord;

			if (null != dr)
			{
				dr.Cells["NotPercent"].Value = .25d;
			}
		}
	}
xmlns:igDP="http://infragistics.com/DataPresenter"
xmlns:igEditors="http://infragistics.com/Editors"
xmlns:sys="clr-namespace:System;assembly=mscorlib"

<igDP:XamDataGrid 
    
x:Name="grid" 
    
BindToSampleData="True"
    
InitializeRecord="grid_InitializeRecord"
    
ClipboardCopying="grid_ClipboardCopying">
    
<igDP:XamDataGrid.Resources>
        
<Style x:Key="expEditor" TargetType="{x:Type igEditors:XamTextEditor}">
            
<Setter Property="Format" Value="E" />
        
</Style>
    
</igDP:XamDataGrid.Resources>

    
<igDP:XamDataGrid.FieldLayoutSettings>
        
<igDP:FieldLayoutSettings 
            
AllowClipboardOperations="All"
            
CopyFieldLabelsToClipboard="False" />
    
</igDP:XamDataGrid.FieldLayoutSettings>
    
    
<igDP:XamDataGrid.FieldLayouts>
        
<igDP:FieldLayout>
            
<igDP:FieldLayout.Fields>
                
<igDP:Field Name="name" Label="Name"/>
                
<igDP:Field Name="salary" Label="$"/>
                
<igDP:Field Name="department" Label="Dept"/>
                
<igDP:Field Name="email" Label="Email"/>
                
<igDP:UnboundField Name="NotPercent">
                    
<igDP:UnboundField.Settings>
                        
<igDP:FieldSettings 
                            
EditAsType="{x:Type sys:Double}"
                            
EditorStyle="{StaticResource expEditor}" />
                    
</igDP:UnboundField.Settings>
                
</igDP:UnboundField>
            
</igDP:FieldLayout.Fields>
        
</igDP:FieldLayout>
    
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also