none
CLIPBRD_E_CANT_OPEN exception when copying to clipboard from a DataGrid RRS feed

  • Question

  • The CLIPBRD_E_CANT_OPEN exception occures when DataGrid row is selected and Ctrl+C combination pressed on a keyboard.

    If I don't hit Ctrl+C right away after launching the application and selecting the DataGrid row, but let it sit idle for a few seconds, then the exception does not happen and the content of the selected row is actually copied to the clipboard.

    Here is the failing code-behind:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Collections.ObjectModel;
    
    namespace WpfDataGrid
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            ObservableCollection<ZDate> _Dates = new ObservableCollection<ZDate>();
    
            public ObservableCollection<ZDate> Dates
            {
                get { return _Dates; }
                set { _Dates = value; }
            }
    
            void InitiallizeDates()
            {
                Dates.Add(new ZDate("1991", "May", "15"));
                Dates.Add(new ZDate("1992", "September", "27"));
                Dates.Add(new ZDate("1993", "June", "1"));
            }
    
            public MainWindow()
            {
                InitializeComponent();
    
                InitiallizeDates();
            }
        }
    
        public class ZDate
        {
            public string Year { get; set; }
            public string Month { get; set; }
            public string Day { get; set; }
    
            public ZDate
            (
                string Year,
                string Month,
                string Day
            )
            {
                this.Year = Year;
                this.Month = Month;
                this.Day = Day;
            }
        }
    }
    
    

     

    and corresponding XAML:

     

    <Window x:Class="WpfDataGrid.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525"
            DataContext="{Binding RelativeSource={RelativeSource Self}}"
        >
        <Grid>
            <DataGrid ItemsSource="{Binding Path=Dates}" HorizontalAlignment="Left" VerticalAlignment="Top" />
        </Grid>
    </Window>
    
    

     

     


    • Edited by Jvis Wednesday, February 1, 2012 11:37 PM
    Wednesday, February 1, 2012 11:21 PM

Answers

  • OK well, just so you know, I can run your example with no errors ever.

    I am testing on an i5, so a few seconds would be a lifetime to my PC, but if you are saying the code above, in a completely new project causes your error, I would suggest it is something on your PC, like antivirus? Are you running terminal services, or HyperV/Virtual PC? Could you take the Debug folder on USB and try it on another machine, laptop or something? I honestly have to say I'd look outside of that simple example you have posted, which I have physically copied and tested for you.

     

    I hope my posts have at least been helpful.

     

    Good luck Jvis!

    Pedro

    • Marked as answer by Jvis Thursday, February 2, 2012 2:34 AM
    Wednesday, February 1, 2012 11:59 PM
    Moderator

All replies

  • Just tested for you, and it works fine for me.

    New project, paste in your example.

    I can run the project, select a row, ctrl-c, then alt-tab and paste the line into notepad just fine.

    I have actually answered another post today regarding that error.

    It happens when the Clipboard is already open (and locked) by something else.

    I gather even Terminal Services can cause it.

    Try a complete reboot, then don't open anything but this code in a new project.

     

    Hope that helps?

     

    Regards,
    Pedro




    Wednesday, February 1, 2012 11:30 PM
    Moderator
  • Hi Pedro,

    Thank you for your response. You replied, while I was updating my post. I discovered that if I hit Ctrl+C after a few seconds then there is no exception. I've never seen such issue before with any other app. There must be something wrong and I don't think it's in the code I posted.

    Regards,

    Jvis

    Wednesday, February 1, 2012 11:45 PM
  • OK well, just so you know, I can run your example with no errors ever.

    I am testing on an i5, so a few seconds would be a lifetime to my PC, but if you are saying the code above, in a completely new project causes your error, I would suggest it is something on your PC, like antivirus? Are you running terminal services, or HyperV/Virtual PC? Could you take the Debug folder on USB and try it on another machine, laptop or something? I honestly have to say I'd look outside of that simple example you have posted, which I have physically copied and tested for you.

     

    I hope my posts have at least been helpful.

     

    Good luck Jvis!

    Pedro

    • Marked as answer by Jvis Thursday, February 2, 2012 2:34 AM
    Wednesday, February 1, 2012 11:59 PM
    Moderator
  • Pedro,

    Thank you for testing my project. I appreciate your help.

    The problem disappeared after I rebooted my computer. It was probably related to a lack of some system resource, for there were many windows and ie/chrome tabs open and virtual memory was over the size of the physical memory, which made the whole system very slow. Strangely though that it was not happening with any other applications.

    So I consider this problem resolved, at least for now.

    Thanks again.

    Best regards,

    Jvis

    Thursday, February 2, 2012 2:40 AM