ClipboardRowPastingEventArgs.IsRowValueValid(ColumnBase, Object, out Exception) Method
Returns whether the specified value can be pasted in the column. If not, returns an exception that describes why the value cannot be pasted.
Namespace: DevExpress.WinUI.Grid
Assembly: DevExpress.WinUI.Grid.v23.2.dll
NuGet Package: DevExpress.WinUI
#Declaration
public bool IsRowValueValid(
ColumnBase column,
object value,
out Exception e
)
#Parameters
Name | Type | Description |
---|---|---|
column | Column |
A grid column. |
value | Object | A pasted value. |
e | Exception | An exception that describes why the value cannot be pasted in the column. |
#Returns
Type | Description |
---|---|
Boolean | true if the specified value can be pasted in the column; otherwise, false. |
#Remarks
If the specified value cannot be pasted in the column, the IsRowValueValid method also returns an exception in the following format:
(Pasted value type) (pasted value) was not recognized as a valid (column type).
#Example
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;
}
}
}