バージョン

ClipboardPasting イベント

DataPresenterCommands.Paste コマンドが実行され、セル値がクリップボードの値に基づいて更新されると発生します。
シンタックス
'宣言
 
Public Event ClipboardPasting As EventHandler(Of ClipboardPastingEventArgs)
public event EventHandler<ClipboardPastingEventArgs> ClipboardPasting
イベント データ

イベント ハンドラが、このイベントに関連するデータを含む、ClipboardPastingEventArgs 型の引数を受け取りました。次の ClipboardPastingEventArgs プロパティには、このイベントの固有の情報が記載されます。

プロパティ解説
Cancel Infragistics.Windows.Controls.Events.CancelableRoutedEventArgsから継承されます。 
DataObject セル値の取得元の System.Windows.IDataObject を返します。
FieldCount Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgsから継承されます。コレクションで表されるフィールド数を返します。
Handled 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 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 Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgsから継承されます。コレクションで表されるレコードの数を返します。
RoutedEvent System.Windows.RoutedEventArgsから継承されます。Gets or sets the System.Windows.RoutedEventArgs.RoutedEvent associated with this System.Windows.RoutedEventArgs instance.
Source System.Windows.RoutedEventArgsから継承されます。Gets or sets a reference to the object that raised the event.
Values Infragistics.Windows.DataPresenter.Events.ClipboardOperationEventArgsから継承されます。クリップボード操作のソースとして使用される、変換されなかった値のコレクションを返します。
解説

このイベントは、関連付けられたセルを更新するために解析された値を提供するために使用できます。

使用例
Imports Infragistics.Windows.DataPresenter
Imports System.Globalization

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

        If fldIndex >= 0 Then
            Dim percentSymbol As String = CultureInfo.CurrentCulture.NumberFormat.PercentSymbol

            For i As Integer = 0 To e.RecordCount - 1
                Dim cvh As CellValueHolder = e.Values(i, fldIndex)

                If Not cvh Is Nothing AndAlso cvh.IsDisplayText AndAlso Not String.IsNullOrEmpty(TryCast(cvh.Value, String)) Then
                    Dim originalValue As String = cvh.Value.ToString()
                    Dim newValue As String = originalValue.Replace(percentSymbol, String.Empty)

                    ' if the source value had a percent...
                    If newValue <> originalValue Then
                        Dim value As Double

                        ' parse the value without the % and divide by 100
                        If Double.TryParse(newValue, NumberStyles.Any, Nothing, value) Then
                            cvh.Value = value / 100
                            cvh.IsDisplayText = False
                        End If
                    End If
                End If
            Next i
        End If
    End Sub

    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
                dr.Cells("Percent").Value = 0.25
            End If
        End If
    End Sub
using Infragistics.Windows.DataPresenter;
using System.Globalization;

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

		if (fldIndex >= 0)
		{
			string percentSymbol = CultureInfo.CurrentCulture.NumberFormat.PercentSymbol;

			for (int i = 0, count = e.RecordCount; i < count; i++)
			{
				CellValueHolder cvh = e.Values[i, fldIndex];

				if (null != cvh && cvh.IsDisplayText && !string.IsNullOrEmpty(cvh.Value as string))
				{
					string originalValue = cvh.Value.ToString();
					string newValue = originalValue.Replace(percentSymbol, string.Empty);

					// if the source value had a percent...
					if (newValue != originalValue)
					{
						double value;

						// parse the value without the % and divide by 100
						if (double.TryParse(newValue, NumberStyles.Any, null, out value))
						{
							cvh.Value = value / 100;
							cvh.IsDisplayText = false;
						}
					}
				}
			}
		}
	}

	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;
				dr.Cells["Percent"].Value = .25d;
			}
		}
	}
<igDP:XamDataGrid 
    
xmlns:igDP="http://infragistics.com/DataPresenter"
    
xmlns:igEditors="http://infragistics.com/Editors"
    
xmlns:sys="clr-namespace:System;assembly=mscorlib"
    
x:Name="grid" 
    
BindToSampleData="True"
    
InitializeRecord="grid_InitializeRecord"
    
ClipboardCopying="grid_ClipboardCopying"
    
ClipboardPasting="grid_ClipboardPasting">
    
<igDP:XamDataGrid.Resources>
        
<Style x:Key="percentEditor" TargetType="{x:Type igEditors:XamTextEditor}">
            
<Setter Property="Format" Value="P2" />
        
</Style>
        
<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="Percent">
                    
<igDP:UnboundField.Settings>
                        
<igDP:FieldSettings 
                            
EditAsType="{x:Type sys:Double}"
                            
EditorStyle="{StaticResource percentEditor}" />
                    
</igDP:UnboundField.Settings>
                
</igDP:UnboundField>
                    
<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>
参照