Back to Devexpress

TreeList.ClipboardNodeCopying Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-15cecee7.md

latest11.8 KB
Original Source

TreeList.ClipboardNodeCopying Event

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.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DXCategory("Action")]
public event ClipboardNodeCopyingEventHandler ClipboardNodeCopying
vb
<DXCategory("Action")>
Public Event ClipboardNodeCopying As ClipboardNodeCopyingEventHandler

Event Data

The ClipboardNodeCopying event's data class is ClipboardNodeCopyingEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelGets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
HeadersProvides access to the collection of cells in the processed column header, or band header.
NodeHandleGets the handle of the processed node.
TypeGets the type of the processed row.
ValuesProvides access to the collection of cells in the processed node.

Remarks

If the ClipboardMode option is set to Formatted, the ClipboardNodeCopying event fires before a node, column headers, or band headers are copied to the clipboard. You can handle this event to apply a format, change the copied data, or skip a data row or header.

Note

Run the DevExpress XtraTreeList demo to see how to copy and paste data.

Row Type

The ClipboardNodeCopying event fires for each processed node and header. The Type event argument returns the processed row type:

  • Row — a tree list node.

  • ColumnHeader — column headers.

  • BandHeader — band headers.

To prevent the processed row from being copied, set the Cancel event argument to true.

Cells

Depending on the row type, use the following collections to access the processed cells:

  • Values — a collection of cells in tree list nodes.
  • Headers — a collection of cells in column headers and band headers.

You can index cells by column/band objects or by field names/band names. The returned object contains view information about the cell. You can specify the following properties:

  • Column — gets a TreeListColumn or TreeListBand object that specifies the processed column or band.
  • Value — gets or sets an object that specifies the cell’s value.
  • BackColor , ForeColor — gets or sets the background and foreground colors for the cell.
  • Font — gets or sets the font of the text displayed in the cell.
  • BorderBottom , BorderLeft , BorderRight , BorderTop — gets or sets BorderInfo structures that allow you to specify the following properties:

Extension Methods

Event arguments also provide the following extension methods that allow you to specify an action that accepts the processed row as a parameter:

  • WithRow — allows you to specify a method that accepts the collection of cell values as a parameter.
  • WithColumnHeader — allows you to specify a method that accepts the collection of column headers as a parameter.
  • WithBandHeaders — allows you to specify a method that accepts the collection of band headers as a parameter.

Note

These extension methods are declared in the DevExpress.XtraTreeList.Printing namespace. Make sure you referenced this namespace in code.

Examples

The code below shows how to change a column header’s caption and appearance.

csharp
using DevExpress.XtraExport.Helpers;
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Columns;

private void TreeList1_ClipboardNodeCopying(object sender, ClipboardNodeCopyingEventArgs e) {    
    switch (e.Type) {
        case ClipboardInfoType.ColumnHeader:
            var salesHeaderInfo = e.Headers[colRegion];
            var salesHeaderInfo1 = e.Headers["Region"];
            if (salesHeaderInfo != null) {
                salesHeaderInfo.BackColor = Color.Red;
                salesHeaderInfo.ForeColor = Color.White;
                salesHeaderInfo.BorderLeft = new ClipboardCellBorderInfo(Color.BlanchedAlmond, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot);
                salesHeaderInfo.BorderTop = new ClipboardCellBorderInfo(Color.Crimson, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot);
                salesHeaderInfo.BorderRight = new ClipboardCellBorderInfo(Color.CornflowerBlue, DevExpress.XtraExport.Helpers.BorderStyle.Dotted);
                salesHeaderInfo.BorderBottom = new ClipboardCellBorderInfo(Color.Red, DevExpress.XtraExport.Helpers.BorderStyle.DashDot);
                salesHeaderInfo.Value = "REGION";
            }
            break;
        case ClipboardInfoType.BandHeader:
            // The code does not copy band headers.
            e.Cancel = true;
            //var salesBandHeaderInfo = e.Headers[treeListBand1];
            //var salesBandHeaderInfo1 = e.Headers["treeListBand1"];
            break;
        case ClipboardInfoType.Row:
            //var regionCellInfo = e.Values[colRegion];
            var regionCellInfo1 = e.Values["Region"];
            if (regionCellInfo1.Value.Equals("France"))
                e.Cancel = true;
            break;
    }
}
vb
Imports DevExpress.XtraExport.Helpers
Imports DevExpress.XtraTreeList
Imports DevExpress.XtraTreeList.Columns

Private Sub treeList1_ClipboardNodeCopying(ByVal sender As Object, ByVal e As ClipboardNodeCopyingEventArgs) _
    Handles treeList1.ClipboardNodeCopying
    Select Case e.Type
        Case ClipboardInfoType.ColumnHeader
            Dim salesHeaderInfo = e.Headers(colRegion)
            'var salesHeaderInfo1 = e.Headers["Region"];
            If salesHeaderInfo IsNot Nothing Then
                salesHeaderInfo.BackColor = Color.Red
                salesHeaderInfo.ForeColor = Color.White
                salesHeaderInfo.BorderLeft = New ClipboardCellBorderInfo(Color.BlanchedAlmond, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot)
                salesHeaderInfo.BorderTop = New ClipboardCellBorderInfo(Color.Crimson, DevExpress.XtraExport.Helpers.BorderStyle.DashDotDot)
                salesHeaderInfo.BorderRight = New ClipboardCellBorderInfo(Color.CornflowerBlue, DevExpress.XtraExport.Helpers.BorderStyle.Dotted)
                salesHeaderInfo.BorderBottom = New ClipboardCellBorderInfo(Color.Red, DevExpress.XtraExport.Helpers.BorderStyle.DashDot)
                salesHeaderInfo.Value = "REGION"
            End If
        Case ClipboardInfoType.BandHeader
            ' The code does not copy band headers.
            e.Cancel = True
            'var salesBandHeaderInfo = e.Headers[treeListBand1];
            'var salesBandHeaderInfo1 = e.Headers["treeListBand1"];
        Case ClipboardInfoType.Row
            'var regionCellInfo = e.Values[colRegion];
            Dim regionCellInfo1 = e.Values("Region")
            If regionCellInfo1.Value.Equals("France") 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.

csharp
using DevExpress.XtraTreeList.Printing;
using DevExpress.XtraTreeList;

private void treeList1_ClipboardNodeCopying(object sender, ClipboardNodeCopyingEventArgs e) {
    e.WithRow(dataRowValues => {
        ClipboardValueInfo austriaValueInfo = dataRowValues.FirstOrDefault((valueInfo) => valueInfo.Value as string == "Austria");
        if (austriaValueInfo != null)
            austriaValueInfo.BackColor = Color.Red;
    });
    e.WithColumnHeader(columnHeaderRowValues => {
        ClipboardHeaderInfo stateColumnHeaderInfo = columnHeaderRowValues.FirstOrDefault((columnHeaderInfo) => columnHeaderInfo.Column == colState);
        if (stateColumnHeaderInfo != null)
            stateColumnHeaderInfo.BackColor = Color.Red;
    });
}
vb
Imports DevExpress.XtraTreeList.Printing
Imports DevExpress.XtraTreeList

Private Sub treeList1_ClipboardNodeCopying(ByVal sender As Object, ByVal e As ClipboardNodeCopyingEventArgs) Handles treeList1.ClipboardNodeCopying
    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.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

ClipboardNodePasting

Clipboard

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace