Tech Off Thread

3 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Requested Clipboard operation did not succeed?

Back to Forum: Tech Off
  • User profile image
    KristenApril

     

    Exception Type: ExternalException
    Message: Requested Clipboard operation did not succeed.
    Method: ThrowIfFailed
    Source: System.Windows.Forms
    Stack Trace:
       at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
       at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
       at System.Windows.Forms.Clipboard.SetText(String text, TextDataFormat format)
       at System.Windows.Forms.Clipboard.SetText(String text)
       at Deerfield.Base.Controls.DataGridView.ProcessCmdKey(Message& msg, Keys keyData) in C:\Users\Developer\Desktop\deerfield\src\core\Deerfield\Deerfield.Base\Controls\DataGridView.cs:line 555

     

     This happened when a user was trying to copy text out of a data grid. For the purpose of simplifything things we use a function to make it easier for the user to take text out. This function takes text out of the data grid and copies it to the clipboard. However, it failed even though the text was not null.

    Here is the function we use to do this:

            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                //simulate a single-cell copy when just a single cell is selected
                if (keyData == (Keys.Control | Keys.C))
                {
                    string text = null;
                    if (EditingControl != null) text = EditingControl.Text;
                    else if (SelectedCells.Count == 1 && SelectedCells[0].Value != null)
                        text = SelectedCells[0].Value.ToString();
    
                    if (!String.IsNullOrEmpty(text))
                    {
                        Clipboard.SetText(text); //can't pass null or empty strings in here, trust me
                        return true;
                    }
                    else return base.ProcessCmdKey(ref msg, keyData);
                }
                else return base.ProcessCmdKey(ref msg, keyData);
            }
     
    Thanks in advance for any help :)
     

     

     

     
     
     

  • User profile image
    davewill

    Which line in your post is 555?

    C:\Users\Developer\Desktop\deerfield\src\core\Deerfield\Deerfield.Base\Controls\DataGridView.cs:line 555

  • User profile image
    KristenApril

    @davewill

    It was line 13 (Clipboard.SetText(text)). But I wound up making a function that would catch the exception and retry the setText(similar to the way Clipboard.setDataObject does it). Thank you though Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.