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