VirtualGrid CUT event handler

1 Answer 36 Views
VirtualGrid
Emanuele
Top achievements
Rank 1
Iron
Iron
Emanuele asked on 29 Oct 2024, 11:23 AM

Hi,

in VirtualGrid, if I use CTRL+X or "Cut" in the default context menu, the "Copying" event handler is fired.

I'm able to customize the context menu and add a specific callback for the "Cut" button.

But is there a way to understand if the "Copying" event handler is fired after the CTRL+X or CTRL+C shortcut? (I'm using the 2024.5.514.48 UI for Winforms version)

Thank you,

 

Emanuele

1 Answer, 1 is accepted

Sort by
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 30 Oct 2024, 11:36 AM

Hi Emanuele,

Thank you for reaching out to us.

The VirtualGridClipboardEventArgs class does not expose such property to get if the Cut or Copy functionality is going to be executed in the Copying event. Upon checking the source code, the key combination is caught in the VirtualGridInputBehavior class. What you can do is create a custom class that derives from VirtualGridInputBehavior as demonstrated in the Input Behavior help article. In the custom VirtualGridInputBehavior class, you can override the HandleUnhandledKeys method. For your convenience, I have extracted the base code of the method.

public class CustomVirtualGridInputBehavior : VirtualGridInputBehavior
{
    public CustomVirtualGridInputBehavior(RadVirtualGridElement gridElement) : base(gridElement)
    {
    }

    protected override bool HandleUnhandledKeys(KeyEventArgs keys)
    {
        //base.HandleUnhandledKeys(keys);

        if (keys.KeyCode == Keys.A && keys.Control)
        {
            this.GridElement.Selection.SelectAll();
            return true;
        }

        if (keys.KeyCode == Keys.C && keys.Control)
        {
            return this.GridElement.CopySelection();
        }

        if (keys.KeyCode == Keys.X && keys.Control)
        {
            return this.GridElement.CutSelection();
        }

        if (keys.KeyCode == Keys.V && keys.Control)
        {
            return this.GridElement.Paste();
        }

        return false;
    }
}

public Form1()
{
    InitializeComponent();
    this.radVirtualGrid1.VirtualGridElement.InputBehavior = new CustomVirtualGridInputBehavior(this.radVirtualGrid1.VirtualGridElement);
    this.radVirtualGrid1.Copying += radVirtualGrid1_Copying;
}

You can raise a flag in the HandleUnhandledKeys method for the specific cut/copy/paste operation and check this flag in the Copying event.

I hope that this approach will work for you.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
VirtualGrid
Asked by
Emanuele
Top achievements
Rank 1
Iron
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or