WPF Datagrid COMException on using IncludeHeader ClipboardCopyMode
Asked Answered
Y

1

9

In my WPF app, I am using a Datagrid control; in the control definition I defined ClipboardCopyMode property as 'IncludeHeader'.

<DataGrid Name="datagrid"  ClipboardCopyMode="IncludeHeader">
</DataGrid>

At times, when I try to copy any data from grid, I am encountering HRESULT clipboard crash error -

System.Runtime.InteropServices.COMException (0x800401D0): 
OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))

Any suggestions to resolve it. I looked at other posts, mostly they are about how to handle this scenario when you explicitly use the Clipboard related methods but none related to Datagrid.

Yachtsman answered 1/6, 2012 at 19:3 Comment(2)
having exactly the same problem with my app. Added a DataGrid, which is displaying data. The app was working fine, until I switched to VS2012 and .net4.5. After that, when I copy the content to clipboard, the app crashesForcer
The answer to Arsen's post on this helped me.Woodford
G
4

Found this from Andrew Smith at http://blogs.infragistics.com/forums/t/35379.aspx -

Technically only 1 process can open the clipboard so if another process has it opened the subsequent requests will fail until the first releases the clipboard. This was sort of handled in the WinForms Clipboard class where it would retry the set with a delay in between each try but the WPF clipboard class doesn't do this so if it fails on the first show the exception occurs. Even then we should probably catch the exception and raise the clipboard operation error if it still fails.

Same thing is explained and some ways to fix it are mentioned on this italian blog -

WPF DataGrid Clipboard BUG (?) & Work

Google Translation

Following MSDN forum thread suggests that this could be machine specific problem, can you reproduce this on other machines? -

CLIPBRD_E_CANT_OPEN exception when copying to clipboard from a DataGrid

Update:

Blog link seems to be down but a cached version can be accessed through this link -

WPF DataGrid Clipboard BUG (?) & Work (Cached translation)

Goldin answered 5/6, 2012 at 7:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.