Skip to main content

Paste Operations

  • 3 minutes to read

Users can paste data from the Clipboard to the GridControl.

Smart Paste

You can apply a smart paste to the GridControl. Refer to the following help topic for more information: Smart Paste.

Paste at Runtime

Users can press Ctrl+V or Ctrl+Insert to paste plain and formatted data into the GridControl.

Data Paste Specifics

  • If a target column cannot accept any value in a pasted row, this row is skipped.
  • Image data is not supported.
  • Read-only and non-editable columns are skipped during pasting in Update paste mode.
  • The paste operation cannot add new rows if the data source does not allow you to add new rows.

Append Data

You can use paste operations to add new rows to the GridControl. In this case, pasted data is added as new rows to the data source, and the GridControl redraws content. The data source should allow you to add new rows to support such paste operations.

The following image demonstrates a paste operation between Microsoft Excel and the GridControl:

Clipboard Pasting Append

Set the TableView.PasteMode (or TreeListView.PasteMode) property to Append to enable paste append operations as demonstrated in the following code example:

<dxg:GridControl>
   <dxg:GridControl.View>
      <dxg:TableView PasteMode="Append" />
   </dxg:GridControl.View>
</dxg:GridControl>

Update Data

You can use paste operations to update populated GridControl cells. The following image demonstrates a paste operation from Excel that updates GridControl cells:

Clipboard Pasting Update

Set the TableView.PasteMode (or TreeListView.PasteMode) property to Update to enable paste operations:

<dxg:GridControl>
   <dxg:GridControl.View>
      <dxg:TableView PasteMode="Update" />
   </dxg:GridControl.View>
</dxg:GridControl>

Paste in Code

You can use the TableView.OnPaste (or TreeListView.OnPaste) method to paste data from the clipboard in the GridControl. The following example updates the required row with clipboard data:

<dxg:GridControl>
   <dxg:GridControl.View> 
      <dxg:TableView Name="view" PasteMode="Update" /> 
   </dxg:GridControl.View> 
</dxg:GridControl>

<Button Click="OnClick">Paste from clipboard</Button>
void OnClick(object sender, RoutedEventArgs e) {
   view.FocusedRowHandle = 5;
   view.OnPaste();
}

Process Paste Operations

The GridControl has events you can handle to customize paste operation behavior and perform additional actions:

Event Description
TableView.ClipboardRowCellValuePasting / TreeListView.ClipboardRowCellValuePasting Occurs for each pasted cell before the corresponding GridControl content update. Handle this event to modify pasted data or prevent the current cell from being updated.
TableView.ClipboardRowPasting / TreeListView.ClipboardRowPasting Occurs for each pasted row immediately before the corresponding GridControl update. Handle this event to modify pasted data or prevent the current row from being updated.
DataControlBase.PastingFromClipboard Occurs in response to a Ctrl+V or Shift+Ins keystroke. Handle this event to implement custom paste operation behavior.

The following example handles the TableView.ClipboardRowCellValuePasting event to remove underscore characters from pasted strings and apply “camel case” formatting:

<dxg:GridControl>
   <dxg:GridControl.View>
      <dxg:TableView PasteMode="Update" ClipboardRowCellValuePasting="OnClipboardRowCellValuePasting" />
   </dxg:GridControl.View>
</dxg:GridControl>
void OnClipboardRowCellValuePasting(object sender, ClipboardRowCellValuePastingEventArgs e) {
   if(e.Column.FieldName == "Group") {
      string pastedString = e.Value.ToString();
      string newString = pastedString.Replace('_', ' ');
      string newCapitalizedString = Regex.Replace(newString, @"(^\w)|(\s\w)", m => m.Value.ToUpper());
      e.Value = newString;
   }
}
See Also