Posted 25 October 2023, 7:59 am EST
Blazor FlexGrid supports clipboard events such as Cut, Copy, and Paste (Ctrl-X, Ctrl-C, and Ctrl-V).
Unfortunately however, corresponding events have not been supplied - namely:
- OnBeforeCopy & OnAfterCopy (aka CellCopyStared & CellCopyEnded)
 - OnBeforeCut & OnAfterCut
 - OnBeforePaste & OnAfterPaste
 
This shortcoming cannot even be mildly compensated by wrapping the FlexGrid with a div event handler such as the following, because the edit events within the FlexGrid get badly corrupted (either editing is not possible at all, or editing gets “undone” immediately … sometimes however, editing will be successful if you are really quick!):
<div @onkeydown="@OnKeyDownHandler">
	    <FlexGrid ItemsSource="@_someDataArray" 
                      StyleKind="@GridStyle.Classic"
		      Style="@("max-height:50vh")" />
</div>
@code{
    protected void OnKeyDownHandler(KeyboardEventArgs e)
    {
        if ("KeyC" == e.Code)
        {
           // React to Ctrl-C event
	   // ...
        }
        else if ("KeyV" == e.Code)
        {
           // React to Ctrl-V event
	   // ...
        }
    }
}
Therefore, I’d like to see the mentioned 6 new events could be provided for.
If I am not entirely mistaken, the implementation would be pretty straight forward:
New Pseudo-Code for “Copy”-Event:
	//
	// Summary:
	//     Occurs before copy of a cellrange is stared.
	[Parameter]
	public EventHandler<GridCellClipboardEventArgs> CellCopyStarted { get; set; }
	//
	// Summary:
	//     Occurs after copy of a cellrange is ended/committed.
	[Parameter]
	public EventHandler<GridCellClipboardEventArgs> CellCopyEnded { get; set; }
        protected internal sealed override void OnCellCopyStarted(GridCellClipboardEventArgs e)
        {
            CellCopyStarted?.Invoke(this, e);
        }
        protected internal sealed override void OnCellCopyEnded(GridCellClipboardEventArgs e)
        {
            CellCopyEnded?.Invoke(this, e);
        }
        //
        // Summary:
        //     Copy the current selection to the clipboard.
        public virtual void Copy()
        {
	    // TODO: Trigger Event "CellCopyStarted" here
	    OnCellCopyStarted(new GridCellClipboardEventArgs() { ... });
            GridCellRange gridCellRange = ((base.SelectionMode == GridSelectionMode.None) ? CursorRange : Selection);
            if (!(gridCellRange == null))
            {
                string clipString = GetClipString(gridCellRange);
                ClipboardEx.SetText(base.Js, clipString);
            }
	    // TODO: Trigger Event "CellCopyEnded" here
	    OnCellCopyEnded(new GridCellClipboardEventArgs() { ... });
        }
Please let me know,
- a) if you can add these events (and if yes, when I can expect the new version to be available) or
 - b) if there is a workaround I just did not see.
 
Thx and best from Hamburg, Germany
Ben.
