Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..
I am woking in VB.NET2008.. In my Project add a Menustrip to give all report name and using Tabcontrol to view by clicking the report.. In that runtime i am clicking reportname an exception is occur..
"dragdrop registration did not succeed"
"Top-level control cannot be added to a control."

This type of exception occur so didnt view the report
What the reason???


Thanks!!!
Posted
Comments
Sergey Alexandrovich Kryukov 2-Feb-11 1:21am    
Needs code, exception dump and indication in what line(s) exceptions were thrown.

If you have the [STAThread] attribute on your Main function, then the main program thread should already be STA. The most likely explanation, then, is that this exception is happening on a different thread. Look at the Threads window in Visual Studio (Debug | Windows | Threads) when the exception occurs and see if you are on a thread other than the main thread. If you are, the solution is probably as simple as setting the thread model for that new thread, which you can do as follows (add this code to the thread where the control is being created):

Thread.CurrentThread.SetApartmentState( ApartmentState.STA )

(Thread and ApartmentState are members of System.Threading)
 
Share this answer
 
v3
The error message "Top-level control cannot be added to a control" is self-explanatory.
It's easy to fix. Before you add a top-level control to a control, you need to set top level to false:

Code:
this.panel1.Toplevel = false;
or
this.panel1.SetTopLevel(false);

Then you need to show the control, using Show(), after it's added to a control.
You can test whether the control is a top level control:
Code:
bool bTopLevel = panel1.TopLevel;
bool bTopLevel = panel1.GetTopLevel();

When the control is not a top level control, it looses all the form level events such as Close().
Since the control is no longer the top level control, it doesn't look like a separate form. To compensate for this, you can add all your controls in a Panel
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900