GridControl.ClipboardRowPasting Event
Occurs before clipboard data is pasted in the GridControl and allows you to process the paste operation.
Namespace: DevExpress.WinUI.Grid
Assembly: DevExpress.WinUI.Grid.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public event ClipboardRowPastingEventHandler ClipboardRowPasting
#Event Data
The ClipboardRowPasting event's data class is ClipboardRowPastingEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Cancel | Gets or sets whether to exclude the processed row from the paste operation’s result. |
Cell |
Gets pasted values. |
Columns | Gets changed columns. |
Original |
Gets the row’s original values. |
Row |
Gets the total number of rows pasted in the Grid |
Row |
Gets the processed row’s handle. |
The event data class exposes the following methods:
Method | Description |
---|---|
Is |
Returns whether the processed row can be pasted in the Grid |
Is |
Returns whether the specified value can be pasted in the column. If not, returns an exception that describes why the value cannot be pasted. |
#Remarks
The GridControl raises the ClipboardRowPasting event for each pasted row. You can use this event to change pasted values or exclude a row from the result.
The following code sample handles the event to replace the Yes and No string values pasted into the Discounted column cells with Boolean values:
<dxg:GridControl ...
x:Name="grid"
PasteMode="Append"
ClipboardRowPasting="grid_ClipboardRowPasting">
<!-- ... -->
</dxg:GridControl>
void grid_ClipboardRowPasting(object sender, DevExpress.WinUI.Grid.ClipboardRowPastingEventArgs e) {
var discColumn = grid.Columns["Discounted"];
// Check if a user pastes any data in the Discounted column:
if (e.CellValues.ContainsKey(discColumn)) {
// Check if the pasted value does not match the column's type:
if (!e.IsRowValueValid(discColumn, e.CellValues[discColumn], out Exception exception)) {
if (Equals(e.CellValues[discColumn], "Yes"))
e.CellValues[discColumn] = true;
else if (Equals(e.CellValues[discColumn], "No"))
e.CellValues[discColumn] = false;
else throw exception;
}
}
}