Please note that this control has been retired and is now obsolete to the XamDataGrid control, and as such, we recommend migrating to that control. It will not be receiving any new features, bug fixes, or support going forward. For help or questions on migrating your codebase to the XamDataGrid, please contact support.
This topic demonstrates how you can paste copied data in the xamGrid™ control and handle errors that may occur when pasting data.
The following table lists the topics required as a prerequisite to understanding this topic.
This topic contains the following sections:
This procedure demonstrates how clipboard data is pasted in the xamGrid control. In case an error occurs, a notification dialog is displayed so the end user can decide how to proceed.
The example below uses paste helper method PasteAsExcel and ClipboardPasteError event.
The following screenshot is a preview of the final result.
To complete the procedure, you need to include the DataUtil class provided for you as a sample data source in your project.
This topic takes you step-by-step toward pasting data and handling pasting errors in the xamGrid. The following is a conceptual overview of the process:
The following steps demonstrate how to use the paste helper method PasteAsExcel and handle the ClipboardPasteError event.
Add a xamGrid control to your application and bind in to data source.
Add handlers for the ClipboardPasting
and ClipboardPasteError
events.
In XAML:
<ig:XamGrid x:Name="dataGrid"
ClipboardPasting="dataGrid_ClipboardPasting"
ClipboardPasteError="dataGrid_ClipboardPasteError">
<!-- Add more code here -->
</ig:XamGrid>
Enable the xamGrid copy and paste features.
In XAML:
<ig:XamGrid.ClipboardSettings>
<ig:ClipboardSettings AllowCopy="True"
CopyOptions="ExcludeHeaders"
CopyType="SelectedCells"
AllowPaste="True"/>
</ig:XamGrid.ClipboardSettings>
The multiple cell selection is enabled in the xamGrid so the end user can select xamGrid cells to copy within.
In XAML:
<ig:XamGrid.SelectionSettings>
<ig:SelectionSettings
CellClickAction="SelectCell"
CellSelection="Multiple" />
</ig:XamGrid.SelectionSettings>
Use the PasteAsExcel
method to perform the pasting within the xamGrid. You can paste either xamGrid or Excel cells content.
In C#:
private void dataGrid_ClipboardPasting(object sender, Infragistics.Controls.Grids.ClipboardPastingEventArgs e)
{
// Paste a rectangular selection of cells in the xamGrid
e.PasteAsExcel();
}
In Visual Basic:
Private Sub dataGrid_ClipboardPasting(sender As Object, e As Infragistics.Controls.Grids.ClipboardPastingEventArgs)
' Paste a rectangular selection of cells in the xamGrid
e.PasteAsExcel()
End Sub
In the ClipboardPasteError
handler, the error type is checked and if the error is recoverable and the pasting can continue.
If the error is recoverable, a confirmation dialog appears and the end user decides if the pasting should continue regardless of the occurred error.
In C#:
private void dataGrid_ClipboardPasteError(object sender, Infragistics.Controls.Grids.ClipboardPasteErrorEventArgs e)
{
// Get the type of the paste error
string strErrorType = e.ErrorType.ToString();
// Check if the pasting can continue after the error
bool isRecoverableError = e.IsRecoverable;
if (isRecoverableError)
{
MessageBoxButton button = MessageBoxButton.OKCancel;
string errorMsg = string.Format("An error occurred during the paste process of type {0}", strErrorType);
string questionMsg = "Do you want to continue?";
MessageBoxResult result = MessageBox.Show(errorMsg + "\n" + questionMsg, "Error Dialog", button);
switch (result)
{
case MessageBoxResult.OK:
e.AttemptRecover = true;
break;
case MessageBoxResult.Cancel:
e.AttemptRecover = false;
break;
}
}
}
In Visual Basic:
Private Sub dataGrid_ClipboardPasteError(sender As Object, e As Infragistics.Controls.Grids.ClipboardPasteErrorEventArgs)
' Get the type of the paste error
Dim strErrorType As String = e.ErrorType.ToString()
' Check if the pasting can continue after the error
Dim isRecoverableError As Boolean = e.IsRecoverable
If isRecoverableError Then
Dim button As MessageBoxButton = MessageBoxButton.OKCancel
Dim errorMsg As String = String.Format("An error occurred during the paste process of type {0}", strErrorType)
Dim questionMsg As String = "Do you want to continue?"
Dim result As MessageBoxResult = MessageBox.Show(errorMsg & vbLf & questionMsg, "Error Dialog", button)
Select Case result
Case MessageBoxResult.OK
e.AttemptRecover = True
Exit Select
Case MessageBoxResult.Cancel
e.AttemptRecover = False
Exit Select
End Select
End If
End Sub
The following topics provide additional information related to this topic.