From f7c76422031e22858532a260367b57dac7e81478 Mon Sep 17 00:00:00 2001 From: Mavaddat Javid <5055400+mavaddat@users.noreply.github.com> Date: Tue, 27 Jan 2026 14:14:11 -0500 Subject: [PATCH 1/2] Handle clipboard exceptions --- src/TableView.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/TableView.cs b/src/TableView.cs index 66f6691..930ef03 100644 --- a/src/TableView.cs +++ b/src/TableView.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -412,7 +413,19 @@ internal void CopyToClipboardInternal(bool includeHeaders) var package = new DataPackage(); package.SetText(GetSelectedClipboardContent(includeHeaders)); - Clipboard.SetContent(package); + + // Try/catch to prevent CLIPBRD_E_CANT_OPEN crashes. + try + { + Clipboard.SetContent(package); + } + catch (Exception ex) + { + // Clipboard failures are normal on Windows (e.g., CLIPBRD_E_CANT_OPEN). + // Swallow to avoid crashing the application. + Debug.WriteLine( + $"TableView: Clipboard.SetContent failed: {ex}"); + } } /// From 7d586d1e5262760760a8547800fa8f9ab1db799d Mon Sep 17 00:00:00 2001 From: Mavaddat Javid <5055400+mavaddat@users.noreply.github.com> Date: Tue, 27 Jan 2026 14:14:53 -0500 Subject: [PATCH 2/2] Skip copy on simple text fields --- src/TableView.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/TableView.cs b/src/TableView.cs index 930ef03..4412b53 100644 --- a/src/TableView.cs +++ b/src/TableView.cs @@ -403,6 +403,14 @@ private TableViewCellSlot GetNextSlot(TableViewCellSlot? currentSlot, bool isShi /// internal void CopyToClipboardInternal(bool includeHeaders) { + // Skip TableView copy logic when a cell editor already handles Ctrl+C. + // TextBox, PasswordBox, and RichEditBox all implement their own copy behavior. + var focused = FocusManager.GetFocusedElement() as FrameworkElement; + if (focused is TextBox || focused is PasswordBox || focused is RichEditBox) + { + return; + } + var args = new TableViewCopyToClipboardEventArgs(includeHeaders); OnCopyToClipboard(args);