TabControl.Controls.Add System.ArgumentException

O

ohmmega

since its common knowledge that it's not possible to hide a tabcontrol
tab, i made a collection for removed pages including their
tabcontrols. removing works pretty fine, but whenever i try to add a
page (timer triggered) i get stuck:

System.ArgumentException

the message is like: controls, created for a thread cannot
superordinate controls from another thread.

*outch*

i hope i made just a small mistake - so anything usefull?

regards
rené

ps: some code:
<code>
foreach(cControlInfo myControlInfo in myContainer.removedControls)
{
if (!
myControlInfo.controlParent.Controls.Contains(myControlInfo.controlChild))
{

myControlInfo.controlParent.Controls.Add(myControlInfo.controlChild);
}
}
</code>
 
G

Guest

You cant finddle with controls from a thread that didnt create them. You
should use a System.Windows.Forms.Timer which fires on the main forms thread
or you should call Invoke on the control to set the property (only really
needed if InvokeRequired property returns true, which it will do from another
thread)

HTH
 
O

ohmmega

*ahm* - i'm using the System.Windows.Forms.Timer control, so what?
can you tell me more about invoke (maybe short snipplet)?

r.
 
N

Nicholas Paldino [.NET/C# MVP]

Here is a link to the documentation for the Invoke method, which
contains a sample:

http://msdn2.microsoft.com/en-us/library/zyzhdc6b.aspx

And are you sure you are using a Windows Timer? The message about
threading indicates that something is not right. Maybe you are not running
the Form in a message pump, maybe you have two message pumps in two threads,
or something... Without seeing your code, it's impossible to tell.

Can you post a complete example which illustrates the problem?
 
O

ohmmega

invoke just did what i needed!

for the curious ones: i've overlooked that my timer starts an
asynchron procedure - *damn*

this works fine:
<code>
//delegate
private delegate delAdder void myAdder(Control cntAddThis);

//in asynchron callback method (mainform)
this.invoke(new delAdder(myAdder), new object[]{cntAdd});
</code>

thank you very much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top