How to get rid of clipboard error - intermittent?

1

Sometimes I get a clipboard error. I've researched this and found that there is a better way to do this, but being new I can't figure out how to integrate it in my code. Trying to make it more stable.

Tried multiple ways to convert the information. Looking to fix this not rewrite everything. I have been down many paths with no luck.

void exportagfile()
    {
        if (editgrid.Items.Count == 0)
        {
            MessageBox.Show("Nothing to export.");
        }
        else
        {
            try
            {

                editgrid.SelectAllCells();
                editgrid.ClipboardCopyMode = 
                DataGridClipboardCopyMode.ExcludeHeader;
                ApplicationCommands.Copy.Execute(null, editgrid);
                String resultat2 = 
              (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
                String result2 = 
                (string)Clipboard.GetData(DataFormats.Text);
                editgrid.UnselectAllCells();
                System.IO.StreamWriter file2 = new 


          System.IO.StreamWriter
          (Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + 
          @"\MI_imp.txt");
                file2.WriteLine(result2.Replace('\t', ',').Replace('ยป', 
                ','));
                file2.Close();

                MessageBox.Show(" Exporting File MI_imp.txt to Desktop");

            }

            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }

        }
    }

Trying to stop error when clipboard tries to open. Error: System.Runtime.InteropServices.COMExeption (0x800401D0) OpenClipboard Failed

c#
wpf
clipboard
asked on Stack Overflow Jul 30, 2019 by CL Worker

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0