שתף באמצעות


DragDrop Registration did not Succeed

Question

Friday, January 6, 2006 9:56 PM

I have an application I've been running under Visual Basic 2003 for some time now without error.
Recently I purchased Visual Studio Professional 2005 and allowed it to convert my project to VS2005. I ran the application and receive "System.InvaliedOperationException: DragDrop Registration did not Succeed"

In my application I found that if I change the AllowDrop for my Treeview to False everything works properly. Th moment I change AllowDrop on my Treeview to True I receive the above error. I know this was a Bug in Beta2 but on a purchased production copy?

Anyway, has anyone seen this error and if so what was done to resolve the problem.

Regards

All replies (7)

Saturday, January 14, 2006 1:51 PM ✅Answered | 2 votes

Delete everything from the BIN directory.


Thursday, August 10, 2006 8:02 PM ✅Answered | 5 votes

Please do the following,

  1. include the following
    using System.Net;
    using System.Threading;

  2. add the [STAThread] Attribute just before ur main function  and also remember to inlcude using System.Net; in ur main program,

[STAThread]
 static void Main()

  1. The steps are as follows for threading,
  1. Put all the code ( for which u r getting this exception) in one function say function A. In the function B in which u are calling ur code,do the following,
    function B
    {
                Thread t = new Thread(new ThreadStart(A));
                t.SetApartmentState(ApartmentState.STA);
                t.Start( );   
    }
    function A
    {
     the code of Windows form..or whatever which is causing the error
    }

Explanation:
It turns out that WF when executing all of its pretty pictures creates a thread to run each of those pictures with.  These threads are in MTA mode (multi threaded apartments) and thus, in .Net 2.0 cannot be used for forms with drag and drop.  so, any code which has AllowDrop Property true will give this error. With this came the following solution.  All of the code used to create the form was placed in a single static function.  The parent function, when it desires to call a new form ( windows form) , creates a thread, in STA mode, to execute this function.  Thus the following code goes in the parent function
            **Thread t = new Thread(new ThreadStart(FormFunction));
            t.SetApartmentState(ApartmentState.STA);
            t.Start( );  

I hope this will help.
Enjoy,
Sneha

**


Monday, August 21, 2006 7:59 PM

Hi, I have a similar problem, can you advise on the best solution?
I have a C# application called from a third party piece of software via VBScript.  The VB script passes an object as a parameter which my application applies changes to.
My C# application dynamically creates a form, which includes controls extended from the RichTextBoxControl.   These controls need to support drag and drop. 
I also need to ensure that the calling application can not receive mouse/keyboard events until my application stops.

I have tried starting my application via a bridging application which starts the app as a separate process (and waits for it to exit) - my app works OK but I can't pass the required parameter.

I have also tried the following code to create my form in a new STA thread:
 //public method called via VB script
 public void launchApp(object oParam)
        {
            Thread t = new Thread(new ParameterizedThreadStart(formCreator));
            t.SetApartmentState(ApartmentState.STA);
            t.Start(oParam);

        }

        //Form creator in separate thread to avoid Drag Drop registration problems
        static public void formCreator(object oParam)
        {
            frmMyDynamicForm frm = new frmMyDynamicForm(oParam);
            frm.ShowDialog();
        }

This has two problems.
1.  Although I don't get Drag and Drop regestration exception, drag and drop still does not work.   Another form allows a drag operation to start OK, and my DragEnter event handler on my extended richTextBoxControl is called but the code " e.Effect = DragDropEffects.Link;" line is ignored and the "Can't drop" icon is displayed.
2.  The calling application can get focus.

I am tearing my hair out (I have only documented a 2 of many attempted solutions), can anyone offer advice?

Any suggestions would be much appreciated.  Thanks!


Monday, August 21, 2006 8:07 PM

Hi, I have a similar problem, can you advise on the best solution?
I have a .NET 2.0  application (actually in C# instead of VB) called from a third party piece of software via VBScript.  The VB script passes an object as a parameter which my application applies changes to.
My C# application dynamically creates a form, which includes controls extended from the RichTextBoxControl.   These controls need to support drag and drop. 
I also need to ensure that the calling application can not receive mouse/keyboard events until my application stops.

I have tried starting my application via a bridging application which starts the app as a separate process (and waits for it to exit) - my app works OK but I can't pass the required parameter.

I have also tried the following code to create my form in a new STA thread:
 //public method called via VB script
 public void launchApp(object oParam)
        {
            Thread t = new Thread(new ParameterizedThreadStart(formCreator));
            t.SetApartmentState(ApartmentState.STA);
            t.Start(oParam);

        }

        //Form creator in separate thread to avoid Drag Drop registration problems
        static public void formCreator(object oParam)
        {
            frmMyDynamicForm frm = new frmMyDynamicForm(oParam);
            frm.ShowDialog();
        }

This has two problems.
1.  Although I don't get Drag and Drop regestration exception, drag and drop still does not work.   Another form allows a drag operation to start OK, and my DragEnter event handler on my extended richTextBoxControl is called but the code " e.Effect = DragDropEffects.Link;" line is ignored and the "Can't drop" icon is displayed.
2.  The calling application can get focus.

I am tearing my hair out (I have only documented a 2 of many attempted solutions), can anyone offer advice?

Any suggestions would be much appreciated.  Thanks!


Wednesday, September 6, 2006 11:47 AM | 1 vote

I deleted everything from my bin directory.........

 

Regards


Tuesday, September 19, 2006 11:08 PM

your two problems:

1.  Although I don't get Drag and Drop regestration exception, drag and drop still does not work.   Another form allows a drag operation to start OK, and my DragEnter event handler on my extended richTextBoxControl is called but the code " e.Effect = DragDropEffects.Link;" line is ignored and the "Can't drop" icon is displayed.

==>> Can you please explain about the line e.Effect = DragDropEffects.Link lil more..
please elaborate the problem ..

2.  The calling application can get focus.

==>> set a global / static flag ( int / bool variable ) which has value 0 before calling the function. When u get into the called function, it becomes 1. Put a check on each operation with this flag that if the flag == 1 , the calling application should not work / cant get focus

Application A
{
 pblic static flag = 0
 call Application B

event mousehover (or any other event/function)
}

event mousehover
{
    if flag == 0
       then only can run the code
}

Application B
{
  flag = 1
}


Tuesday, September 23, 2008 11:47 AM

Hi Computerguy1,
you rule