PC Review


Reply
Thread Tools Rate Thread

strange problem adding child node to a parent node

 
 
=?Utf-8?B?TXJOb2JvZHk=?=
Guest
Posts: n/a
 
      9th Jan 2005
Ok, so I'm absoultely positive this was working last night, but today I'm
getting this error in my program when I try to add a child node to a parent
node of a tree...

The error says:

Message: 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.
Stack Trace: at System.Windows.Forms.TreeNode.Realize()
at System.Windows.Forms.TreeNodeCollection.Add(TreeNode node)
at test.MyNode.AddChild(MyBaseNode node) in ...

So what does this all mean? By the time this error occurs it has already
gone through this same method adding about 30 nodes (confirmed by output)....


 
Reply With Quote
 
 
 
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      10th Jan 2005
Hi,

The error message says it all - you are most likely accessing the TreeView
control from a worker thread, which is prohibited.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"MrNobody" <(E-Mail Removed)> wrote in message
news:9CB5C5D8-5E12-43FB-9CC8-(E-Mail Removed)...
> Ok, so I'm absoultely positive this was working last night, but today I'm
> getting this error in my program when I try to add a child node to a
> parent
> node of a tree...
>
> The error says:
>
> Message: 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.
> Stack Trace: at System.Windows.Forms.TreeNode.Realize()
> at System.Windows.Forms.TreeNodeCollection.Add(TreeNode node)
> at test.MyNode.AddChild(MyBaseNode node) in ...
>
> So what does this all mean? By the time this error occurs it has already
> gone through this same method adding about 30 nodes (confirmed by
> output)....
>
>


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TXJOb2JvZHk=?=
Guest
Posts: n/a
 
      10th Jan 2005
Thanks for your reply! Well, I'm not exactly accessing a Treeview from a
worker thread, what I'm doing is having a worker thread create a root
TreeNode and then add children to it, then later when everything is done and
I'm ready to display this to the UI , I create the dialog, the TreeView and
just add this root node.

Do I have to take the extreme step of creating a non-tree-specific structure
in this worker thread, then once I'm ready for the UI to convert it into a
tree?

"Dmitriy Lapshin [C# / .NET MVP]" wrote:

> Hi,
>
> The error message says it all - you are most likely accessing the TreeView
> control from a worker thread, which is prohibited.
>

 
Reply With Quote
 
Dmitriy Lapshin [C# / .NET MVP]
Guest
Posts: n/a
 
      11th Jan 2005
I think you can create the hierarchy of TreeNodes on a worker thread, but
once the hierarchy is ready, the rest should happen on the UI thread.
In particular, make sure you assign the root node to the treeview on the UI
thread.

If you still get the exception, you will indeed have to create a parallel
hierarchical structure on the worker thread and to convert it to tree nodes
on the UI thread.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"MrNobody" <(E-Mail Removed)> wrote in message
news:B2BBEF9E-FF5A-474F-B197-(E-Mail Removed)...
> Thanks for your reply! Well, I'm not exactly accessing a Treeview from a
> worker thread, what I'm doing is having a worker thread create a root
> TreeNode and then add children to it, then later when everything is done
> and
> I'm ready to display this to the UI , I create the dialog, the TreeView
> and
> just add this root node.
>
> Do I have to take the extreme step of creating a non-tree-specific
> structure
> in this worker thread, then once I'm ready for the UI to convert it into a
> tree?
>
> "Dmitriy Lapshin [C# / .NET MVP]" wrote:
>
>> Hi,
>>
>> The error message says it all - you are most likely accessing the
>> TreeView
>> control from a worker thread, which is prohibited.
>>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get child node of selected parent node jcoon Microsoft Dot NET 9 13th Aug 2009 01:59 PM
When Child node check parent node has to be checked intreeview asp.net 2.0 Janarthanan Lakshmanan Microsoft C# .NET 0 30th Aug 2007 05:06 PM
passing data child parent parent child Maarten Microsoft C# .NET 3 21st Nov 2005 05:13 PM
is there an event that fires when a child control is added to a parent container control (ie child panel added to a parent panel)? notu Microsoft Dot NET Compact Framework 1 19th Jul 2005 07:34 PM
Parent/Child Components: How to make the child components go away when deleting the Parent. Patrick Vanden Driessche Microsoft VB .NET 5 14th Nov 2003 11:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:09 PM.