treenode.nodes.add and invoke

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

I have a tree node object with a function that adds nodes to itself
(as it is expanded). I would like to do this on a worker thread, which
I do when I create the first level of nodes.

However, whilst Treeview has an invoke method, TreeNode does not appear
to. Obvioulsy I need to call the invoke method of the TreeNode in
order to add the sub nodes on the same thread that the parent node was
created on.

Where is the invoke method of TreeNode?
 
Take a look at my posting on 'BackgroundWorker' in languages.csharp forum
posted on 4.13.2006. I went through nearly exactly the same problems and
got it resolved sweetly in the end -- last posting in the string should be
helpful.

Jamie Bissett
 
Kevin said:
I have a tree node object with a function that adds nodes to itself
(as it is expanded). I would like to do this on a worker thread, which
I do when I create the first level of nodes.

However, whilst Treeview has an invoke method, TreeNode does not appear
to. Obvioulsy I need to call the invoke method of the TreeNode in
order to add the sub nodes on the same thread that the parent node was
created on.

Where is the invoke method of TreeNode?

Use the one on the TreeView which you can reach from the node.

Actually you can use the Invoke on ANY control created by the same thread
that created the TreeView (which normally means any control at all).

I don't see why you need a thread to do it though - you can do lazy
expansion perfectly well without it by just getting one level deeper than is
shown expanded.
 
Hi Nick, thanks for your reply.

I'm not sure I understand when you say:
"Use the one on the TreeView which you can reach from the node."
I know that I can reach the nodes.add method of the treeview, but this
will add the nodes at the top of the tree, I need to add them to the
node that we are currently dealing with.

Also I dont understand what you mean when you say that you can use
invoke on any control. This is exaclty what I am saying, there is no
invoke method for a treenode.

Thanks
Kevin
 
Hi Jamie, thanks for your reply.

I had a look at your thread but i'm not sure how it applies to me. I
already have a tree that is 3 levels deep (built earlier on) but once
they get down to these lower levels, I need to do a database query in
order to add more (lower level) nodes to the node that was expanded.

Thanks
Kevin
 
Kevin said:
Hi Nick, thanks for your reply.

I'm not sure I understand when you say:
"Use the one on the TreeView which you can reach from the node."
I know that I can reach the nodes.add method of the treeview, but this
will add the nodes at the top of the tree, I need to add them to the
node that we are currently dealing with.

I mean use the Invoke method on the TreeView. The delegate that you supply
does not have to add nodes at the root - it can add them anywhere.

Basically, when the delegate gets invoked it will be running in the proper
thread to do what it likes to ANY control created on the UI thread (normally
this means any control in your app).
Also I dont understand what you mean when you say that you can use
invoke on any control. This is exaclty what I am saying, there is no
invoke method for a treenode.

The Invoke method on a control is not "for" that control, it is for the UI
thread that created that control.

If it wasn't for the fact that you can have multiple UI threads (which is
rarely used) it would be a static method on some UI utility class (I believe
that that is how it is done in java)

In a typical simple app. Invoke on ANY control will have exactly the same
effect.

TreeNodes should just be considered as part of the TreeView.
 
Ah! I see, for some reason i thought that if i called treeview.invoke,
I would have to add the nodes to the tree, but of course you are right.

Yes, it all becomes clear! It would make more sense to have it as a
static method.

Thanks for your help, much appreciated.
Kevin
 
Back
Top