仅在剪贴板中复制pivotgrid中的字段

时间:2013-06-03 18:57:26

标签: vb.net devexpress

当用户点击一行(或列)字段时,我正在搜索在剪贴板内复制的方法。 示例:当用户单击行(或列)“hello world”并按下ctrl + c时,它会在“hello world”中填充剪贴板。

提前感谢!

2 个答案:

答案 0 :(得分:1)

我实现了Ctrl + C复制快捷方式,我所做的就是处理WinForm控件的KeyDown事件:

private static void OnKeyDown(object sender, KeyEventArgs e)
{
    // Retrieve sender + view here

    if (e.Control && e.KeyCode == Keys.C)
    {
        Clipboard.SetText(view.GetFocusedDisplayText());
        e.Handled = true;
    }
}

希望有所帮助!

答案 1 :(得分:1)

我发现了一种方法。关于PivotGridControl上的MouseClick事件。

  

Dim _point As Point = Nothing

Private Sub PivotGridControl1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles PivotGridControl1.KeyDown
    If _point.IsEmpty Then
    Else
        If e.KeyCode = Keys.C AndAlso e.Control Then
            Dim field As DevExpress.XtraPivotGrid.PivotFieldValueHitInfo = PivotGridControl1.CalcHitInfo(_point).ValueInfo
            Clipboard.SetText(field.Value.ToString())
            e.Handled = True
        End If
    End If
End Sub

Private Sub PivotGridControl1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles PivotGridControl1.MouseClick
    PivotGridControl1.OptionsBehavior.CopyToClipboardWithFieldValues = True

    Dim pt As Point = New Point(e.X, e.Y)

    If PivotGridControl1.CalcHitInfo(pt).HitTest = DevExpress.XtraPivotGrid.PivotGridHitTest.Value Then
        _point = pt
    Else
        _point = Nothing
    End If
End Sub

感谢大家的帮助