windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-357a1ec6.md
Fires before a data row, a group row, column headers, or band headers are copied to the clipboard. Allows you to apply a format, change copied data, or skip a data row or header.
Namespace : DevExpress.XtraGrid.Views.Grid
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("Action")]
public event ClipboardRowCopyingEventHandler ClipboardRowCopying
<DXCategory("Action")>
Public Event ClipboardRowCopying As ClipboardRowCopyingEventHandler
The ClipboardRowCopying event's data class is ClipboardRowCopyingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Cancel | Gets or sets whether to cancel copying the processed row to the clipboard. |
| Headers | Provides access to the collection of cells in the processed column header, or band header. |
| RowHandle | Returns the row handle of a row that triggered this event. |
| Type | Gets the type of the processed row. |
| Values | Provides access to the collection of cells in the processed data row, group row, or summaries in the group row. |
If the ClipboardMode option is set to Formatted, the ClipboardRowCopying event fires before a data row, a group row, a group summary, column headers, or band headers are copied to the clipboard. You can handle this event to change the copied value, customize the cell appearance, or skip certain rows.
Note
Run the DevExpress XtraGrid demo to see how to copy and paste data.
The ClipboardNodeCopying event fires for each processed row and header. The Type event argument returns the processed row type:
Row — a data row.
ColumnHeader — column headers.
BandHeader — band headers.
Group — a group row.
GroupSummary — a group row with summaries.
To prevent the processed row from being copied, set the Cancel event argument to true.
Depending on the row type, use the following collections to access the processed cells:
You can index cells by column/band objects or by field names/band captions. The returned object contains view information about the cell. You can specify the following properties:
Event arguments also provide the following extension methods that allow you to specify an action that accepts the processed row as a parameter:
Note
These extension methods are declared in the DevExpress.XtraGrid.Views.Printing namespace. Make sure you referenced this namespace in code.
The code below shows how to change a column header’s caption and appearance.
using DevExpress.XtraExport.Helpers;
using DevExpress.XtraGrid.Views.Grid;
private void gridView1_ClipboardRowCopying(object sender, ClipboardRowCopyingEventArgs e) {
switch (e.Type) {
case ClipboardInfoType.ColumnHeader:
var columnHead = e.Headers[colSales];
//var columnHead1 = e.Headers["Sales"];
columnHead.BackColor = Color.Red;
columnHead.ForeColor = Color.White;
columnHead.Value = "SALES";
columnHead.BorderLeft = new ClipboardCellBorderInfo(Color.BlanchedAlmond, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot);
columnHead.BorderTop = new ClipboardCellBorderInfo(Color.Crimson, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot);
columnHead.BorderRight = new ClipboardCellBorderInfo(Color.CornflowerBlue, DevExpress.XtraExport.Helpers.BorderStyle.Dotted);
columnHead.BorderBottom = new ClipboardCellBorderInfo(Color.Red, DevExpress.XtraExport.Helpers.BorderStyle.DashDot);
break;
case ClipboardInfoType.Group:
e.Cancel = true;
break;
case ClipboardInfoType.Row:
//var regionCellInfo = e.Values[colState];
var regionCellInfo1 = e.Values["State"];
if (regionCellInfo1.Value.Equals("California"))
e.Cancel = true;
break;
}
}
Imports DevExpress.XtraExport.Helpers
Imports DevExpress.XtraGrid.Views.Grid
Private Sub gridView1_ClipboardRowCopying(ByVal sender As Object, ByVal e As ClipboardRowCopyingEventArgs) _
Handles gridView1.ClipboardRowCopying
Select Case e.Type
Case ClipboardInfoType.ColumnHeader
Dim columnHead = e.Headers(colSales)
'var columnHead1 = e.Headers["Sales"];
columnHead.BackColor = Color.Red
columnHead.ForeColor = Color.White
columnHead.Value = "SALES"
columnHead.BorderLeft = New ClipboardCellBorderInfo(Color.BlanchedAlmond, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot)
columnHead.BorderTop = New ClipboardCellBorderInfo(Color.Crimson, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot)
columnHead.BorderRight = New ClipboardCellBorderInfo(Color.CornflowerBlue, DevExpress.XtraExport.Helpers.BorderStyle.Dotted)
columnHead.BorderBottom = New ClipboardCellBorderInfo(Color.Red, DevExpress.XtraExport.Helpers.BorderStyle.DashDot)
Case ClipboardInfoType.Group
e.Cancel = True
Case ClipboardInfoType.Row
'var regionCellInfo = e.Values[colState];
Dim regionCellInfo1 = e.Values("State")
If regionCellInfo1.Value.Equals("California") Then
e.Cancel = True
End If
End Select
End Sub
The code below shows how to use extension methods to access the processed cell values, column and band headers, groups, and group summaries.
using DevExpress.XtraGrid.Views.Printing;
using DevExpress.XtraGrid.Views.Grid;
private void gridView1_ClipboardRowCopying(object sender, ClipboardRowCopyingEventArgs e) {
e.WithRow(dataRowValues => {
ClipboardValueInfo austriaValueInfo = dataRowValues.FirstOrDefault((valueInfo) => valueInfo.Value as string == "Austria");
if (austriaValueInfo != null)
austriaValueInfo.BackColor = Color.Red;
});
e.WithGroup(groupRowValue => {
if (groupRowValue.Column == colState)
{
groupRowValue.Value = "CLASSIFIED";
}
});
e.WithGroupSummary(groupRowSummaryValues => {
ClipboardValueInfo stateColumnHeaderInfo = groupRowSummaryValues.FirstOrDefault((columnHeaderInfo) => columnHeaderInfo.Column == colState);
if (stateColumnHeaderInfo != null)
stateColumnHeaderInfo.ForeColor = Color.Black;
});
e.WithColumnHeader(columnHeaderRowValues => {
ClipboardHeaderInfo stateColumnHeaderInfo = columnHeaderRowValues.FirstOrDefault((columnHeaderInfo) => columnHeaderInfo.Column == colState);
if (stateColumnHeaderInfo != null)
stateColumnHeaderInfo.BackColor = Color.Red;
});
}
Imports DevExpress.XtraGrid.Views.Printing
Imports DevExpress.XtraGrid.Views.Grid
Private Sub gridView1_ClipboardRowCopying(ByVal sender As Object, ByVal e As ClipboardRowCopyingEventArgs) Handles gridView1.ClipboardRowCopying
e.WithRow(Sub(dataRowValues)
Dim austriaValueInfo As ClipboardValueInfo = dataRowValues.FirstOrDefault(Function(valueInfo) TryCast(valueInfo.Value, String) = "Austria")
If austriaValueInfo IsNot Nothing Then
austriaValueInfo.BackColor = Color.Red
End If
End Sub)
e.WithGroup(Sub(groupRowValue)
If groupRowValue.Column = colState Then
groupRowValue.Value = "CLASSIFIED"
End If
End Sub)
e.WithGroupSummary(Sub(groupRowSummaryValues)
Dim stateColumnHeaderInfo As ClipboardValueInfo = groupRowSummaryValues.FirstOrDefault(Function(columnHeaderInfo) columnHeaderInfo.Column = colState)
If stateColumnHeaderInfo IsNot Nothing Then
stateColumnHeaderInfo.ForeColor = Color.Black
End If
End Sub)
e.WithColumnHeader(Sub(columnHeaderRowValues)
Dim stateColumnHeaderInfo As ClipboardHeaderInfo = columnHeaderRowValues.FirstOrDefault(Function(columnHeaderInfo) columnHeaderInfo.Column = colState)
If stateColumnHeaderInfo IsNot Nothing Then
stateColumnHeaderInfo.BackColor = Color.Red
End If
End Sub)
End Sub
See Also