Skip to main content
A newer version of this page is available. .

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.v22.1.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.
CellValues Gets pasted values.
Columns Gets changed columns.
OriginalCellValues Gets the row’s original values.
RowCount Gets the total number of rows pasted in the GridControl.
RowHandle Gets the processed row’s handle.

The event data class exposes the following methods:

Method Description
IsRowValid() Returns whether the processed row can be pasted in the GridControl.
IsRowValueValid(ColumnBase, Object, out Exception) 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:

WinUI Grid - ClipboardRowPasting Event

<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;
        }
    }
}
See Also