Adding a node to a treeview from a different thread 
Author Message
 Adding a node to a treeview from a different thread

When I try to add a node to a treeview from a different thread, I get an
error, and it tells me to use the Control.Invoke method.

How do I use this? Or are there any other ways to do it?

Thanks

Sam



Tue, 11 Jan 2005 23:13:25 GMT  
 Adding a node to a treeview from a different thread
Hi,
You can only access a Windows Form (and the controls contained within it)
from the Form's own thread, not a different thread.

The "Invoke" method is used to call a routine on the Form using that Form's
own thread.  It should allow you to call a Sub/Function by name, and specify
any parameters for that routine if necessary, from a different thread.  I
would suggest checking out the help on the Invoke command.

Cheers,
Alex Clark

Quote:

> When I try to add a node to a treeview from a different thread, I get an
> error, and it tells me to use the Control.Invoke method.

> How do I use this? Or are there any other ways to do it?

> Thanks

> Sam



Wed, 12 Jan 2005 06:04:12 GMT  
 Adding a node to a treeview from a different thread
The Windows Forms controls are thread-affiliated. You can't access a
control's handler with another thread that doesn't create it. You may need
to call the Invoke method of the control to access the control from anoher
thread, or you can use the MethodInvoker class to do it.

David Yuan
This posting is provided "AS IS" with no warranties, and confers no rights.
"Got .Net?  http://www.gotdotnet.com".  



Fri, 14 Jan 2005 19:58:06 GMT  
 Adding a node to a treeview from a different thread
That's what they all say

I have still to find an example which illustrates how to use Invoke
correctly, and have it work in this context.

Any ideas anyone?


Quote:
> The Windows Forms controls are thread-affiliated. You can't access a
> control's handler with another thread that doesn't create it. You may need
> to call the Invoke method of the control to access the control from anoher
> thread, or you can use the MethodInvoker class to do it.

> David Yuan
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> "Got .Net?  http://www.gotdotnet.com".



Mon, 17 Jan 2005 02:40:57 GMT  
 Adding a node to a treeview from a different thread
See
ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbtskManipulatingControlsFromThreads.
htm

Watch word wrap

HTH

David


Quote:
> That's what they all say

> I have still to find an example which illustrates how to use Invoke
> correctly, and have it work in this context.

> Any ideas anyone?



> > The Windows Forms controls are thread-affiliated. You can't access a
> > control's handler with another thread that doesn't create it. You may
need
> > to call the Invoke method of the control to access the control from
anoher
> > thread, or you can use the MethodInvoker class to do it.

> > David Yuan
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> > "Got .Net?  http://www.gotdotnet.com".



Sun, 16 Jan 2005 06:34:06 GMT  
 Adding a node to a treeview from a different thread
The documentation on it is poor, and is confusing. however i managed to get
it working as follows:

' At the top of my form I declare the invoker sub:
Public Delegate Sub TreeInvoker(ByVal key As String)

' When I want to add a tree node from within a worker thread,
' I call the invoker sub as follows, always passing the params as an
' array even when there's only one.
Dim params() As Object = {key}
Me.Invoke(New TreeInvoker(AddressOf Me.AddClientNode), params)

' This is the GUI sub
Private Sub AddClientNode(ByVal key As String)
    Dim n As New Infragistics.Win.UltraWinTree.UltraTreeNode()
    n.Text = key
    n.LeftImages.Add(3)
    n.Key = key
    n.Selected = False
    ultTree.Nodes.Add(n)
End Sub

Sam



Mon, 17 Jan 2005 15:58:00 GMT  
 Adding a node to a treeview from a different thread
Cheers Sam, I'll give it a try

Quote:

> The documentation on it is poor, and is confusing. however i managed to
get
> it working as follows:

> ' At the top of my form I declare the invoker sub:
> Public Delegate Sub TreeInvoker(ByVal key As String)

> ' When I want to add a tree node from within a worker thread,
> ' I call the invoker sub as follows, always passing the params as an
> ' array even when there's only one.
> Dim params() As Object = {key}
> Me.Invoke(New TreeInvoker(AddressOf Me.AddClientNode), params)

> ' This is the GUI sub
> Private Sub AddClientNode(ByVal key As String)
>     Dim n As New Infragistics.Win.UltraWinTree.UltraTreeNode()
>     n.Text = key
>     n.LeftImages.Add(3)
>     n.Key = key
>     n.Selected = False
>     ultTree.Nodes.Add(n)
> End Sub

> Sam



Wed, 19 Jan 2005 03:08:09 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Adding TreeView nodes in separate thread

2. adding a node to treeview from another thread

3. Add a node to treeview under thread

4. Setting different tooltips for different TreeView nodes

5. treeview node count not incrementing when adding new nodes

6. Move Treeview Child Node To Different Parent

7. Set Treeview Nodes to different TextColor

8. Different colors for Treeview nodes?

9. Moving Treeview Node to same level but different position

10. TreeView : How to set a different color to node's Caption

11. TreeView : How to set a different color to node's Caption

12. TreeView : How to set a different color to node's Caption

 

 
Powered by phpBB® Forum Software