CLIPBRD_E_CANT_OPEN error when setting the Clipboard from .NET

前端 未结 7 1202
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 08:08

Why does the following code sometimes causes an Exception with the contents \"CLIPBRD_E_CANT_OPEN\":

Clipboard.SetText(str);

This usually o

7条回答
  •  甜味超标
    2020-11-29 08:28

    This happen to me in my WPF application. I got OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN)).

    i use

    ApplicationCommands.Copy.Execute(null, myDataGrid);
    

    solution is to clear the clipboard first

    Clipboard.Clear();
    ApplicationCommands.Copy.Execute(null, myDataGrid);
    

提交回复
热议问题