Add a node to treeview under thread 
Author Message
 Add a node to treeview under thread

Hi,

I am having exactly the same problem (In VB.NET).
I tried ot in the same way, and made it as you described here.
But I now get another exception:

An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.

I was not able to find some usefull information regarding this
exception.
Maybe it would be very helpfully if you could send a small working
sample into this group.

Thank you,
Andre Lorbach

Quote:

> > Welson,

> >     I should have clairified.  There is an Invoke method on the Control
> > class (and every class that derives from it), that will call the method on
> > the appropriate thread.  You don't want to call the InvokeMember method on
> > the type.

> > --
> >                               - Nicholas Paldino [MVP]



> > > yes,but I use the invoke ,it give me another error.

> > > object [] obj = new object[] {objNode};
> > > Type t=treeView1.GetType();

>  t.InvokeMember("Add",System.Reflection.BindingFlags.Default|System.Reflectio
> > > n.BindingFlags.InvokeMethod,null,treeView1.Nodes,obj);

> > > the error :An unhandled exception of type 'System.MissingMethodException'
> > > occurred in mscorlib.dll

> > > Additional information: Attempted to access a missing member.



> > > > Welson,

> > > >     Any calls made to a class that represents a UI element should be
> >  made
> >  on
> > > > the same thread that the element was created on.  You are probably
>  getting
> > > > these errors for that reason.

> > > >     You should use the Invoke method to make the call you want from
>  another
> > > > thread.

> > > > --
> > > >                               - Nicholas Paldino [MVP]



> > > > > help me!!
> > > > > I want to add a node use the following code

> > > > > private button1_click(object sender, System.EventArgs e)
> > > > > {
> > > > >     Thread th1=new Thread(new ThreadStart(DoWith));
> > > > >     th1.Start();
> > > > > }

> > > > > private void DoWith()
> > > > > {

> > > > >     TreeNode objNode=new TreeNode("This is only a test");
> > > > >     treeView1.Nodes.Add(objNode);

> > > > > }

> > > > > its give me error;but when I add text to TextBox and add a item to
>  Combox,
> > > > > it works well.
> > > > > I want to know does there any diferrence with them.

> > > > > it's the error:

> > > > > An unhandled exception of type 'System.InvalidOperationException'
>  occurred
> > > > > in system.windows.forms.dll

> > > > > Additional information: The action being performed on this control is
>  being
> > > > > called from the wrong thread. You must marshal to the correct thread
>  using
> > > > > Control.Invoke or Control.BeginInvoke to perform this action.

> > > > > welson



Sun, 23 May 2004 18:27:16 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Adding a node to a treeview from a different thread

2. Adding TreeView nodes in separate thread

3. adding a node to treeview from another thread

4. treeview node count not incrementing when adding new nodes

5. Adding nodes to Treeview

6. Adding Nodes to TreeView and XML files

7. Recursive TreeView (adding extra nodes)

8. TreeView Add Node

9. Adding Treeview nodes

10. Add treeview node

11. Treeview, scroll to newly added/selected nodes?

12. TREEVIEW ADD NODE

 

 
Powered by phpBB® Forum Software